develooper Front page | perl.perl5.porters | Postings from August 2008

Re: [perl #58218] backwards logic in perluniintro (5.10.0)

Thread Previous | Thread Next
From:
Dr.Ruud
Date:
August 23, 2008 01:10
Subject:
Re: [perl #58218] backwards logic in perluniintro (5.10.0)
Message ID:
20080823081032.32162.qmail@lists.develooper.com
Brad Baxter schreef:
> # New Ticket Created by  Brad Baxter
> # Please include the string:  [perl #58218]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=58218 >
> 
> 
> -- Perl 5.10.0 documentation --
> http://perldoc.perl.org/perluniintro.html#Questions-With-Answers
> 
> How Do I Detect Data That's Not Valid In a Particular Encoding?
> 
> Use the Encode package to try converting it. For example,
> 
>     use Encode 'decode_utf8';
>     eval { decode_utf8($string, Encode::FB_CROAK) };
>     if ($@) {
>         # $string is valid utf8
>     } else {
>         # $string is not valid utf8
>     }
> 
> Should be
> 
>     use Encode 'decode_utf8';
>     eval { decode_utf8($string, Encode::FB_CROAK) };
>     if ($@) {
>         # $string is not valid utf8
>     } else {
>         # $string is valid utf8
>     }

Alternative-1:

     use Encode 'decode_utf8';
     if ( eval {
            decode_utf8($string, Encode::FB_CROAK);
            1;
          }
        )
         # $string is valid utf8
     } else {
         # $string is not valid utf8
     }



Alternative-2:

     use Encode 'decode_utf8';
     eval {
         decode_utf8($string, Encode::FB_CROAK);
         1;
     }
     or do {
         # $string is not valid utf8
     };

-- 
Affijn, Ruud

"Gewoon is een tijger."

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About