简体   繁体   中英

Is there a difference between “utf8::upgrade” and “is_utf8/decode 'latin1'”?

Do these two code snippets the same thing?

utf8::upgrade( $s );

use Encode qw(is_utf8 decode);

$s = is_utf8( $s ) ? $s : decode( 'latin1', $s );

Making a copy and the implications of such aside, they're the same thing, but only because of how decode('latin1', $_) handles invalid latin1 strings such as "\\x90" .

The expression returns something different (number of bytes used internally vs $s ), but I presumed you're discarding that.

I hope you ask because you want to replace the latter with the former!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM