[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: [perl #58218] backwards logic in perluniintro (5.10.0)
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."
- Follow-Ups from:
-
"Rafael Garcia-Suarez" <rgarciasuarez@gmail.com>
- References to:
-
Brad Baxter (via RT) <perlbug-followup@perl.org>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]