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

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

Thread Previous
From:
Rafael Garcia-Suarez
Date:
August 24, 2008 07:40
Subject:
Re: [perl #58218] backwards logic in perluniintro (5.10.0)
Message ID:
b77c1dce0808240739p6741737cq98cfb0ee2f7adda0@mail.gmail.com
2008/8/23 Dr.Ruud <rvtol+news@isolution.nl>:
>> 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
>     }
>

I chose that one. Thanks, applied as #34223.

Thread Previous


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