Perl5.8.5ãã5.14.2ã«ãããæååããã話
RHEL4ã®ãµãã¼ãæéã延é·ãªãã ã¨ä»æ¥ã§æå¾ã
Red Hat Enterprise Linux - Wikipedia
æ¨æºã®Perlã®ãã¼ã¸ã§ã³ã¯5.8.5ã
ã¨ããããã§å
æ¥RHEL5ã«ããã¨åæã«5.14.2ã«ãã¦ãããï¼ãã¨ææ°è¾¼ãã§perlbrewã§å
¥ããã(RHEL5ã®ããã©ã¯Perl5.8.8)ãæ¢åã®ã·ã¹ãã ã§æååãããã
å®éã«æååãããã®ã¯ãEncode.pmã®decode_utf8()ã使ç¨ãã¦ããç®æã
Perl5.8.5ã®Encode.pmã®ãã¼ã¸ã§ã³ã¯2.01ãPerl5.14.2ã®æ¹ã¯2.42_01ã ã£ãã
ãã£ã¡ãã¡ãããªï¼
ãã¾ã深追ãããªãã£ãããã©ã2.01ã®PPçã®decode_utf8ã¯ä»¥ä¸ã®ã³ã¼ãã ã£ãã
sub decode_utf8($;$) { my ($str, $check) = @_; if ($check){ return decode("utf8", $str, $check); }else{ return undef unless utf8::decode($str); return $str; } }
ãã¼åç´ã«decode("utf8", $str)ã®ã¨ã¤ãªã¢ã¹ã¿ãããªæããã¼ã¨æã£ã¦ã2.42_01ã®æ¹è¦ããã ãã¶å¤ãã£ã¦ããã
sub decode_utf8($;$) { my ( $octets, $check ) = @_; return $octets if is_utf8($octets); return undef unless defined $octets; $octets .= '' if ref $octets; $check ||= 0; $utf8enc ||= find_encoding('utf8'); my $string = $utf8enc->decode( $octets, $check ); $_[0] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() ); return $string; }
ãã£ã¡ãã¡ãããªï¼
404 Blog Not Found:#perl - utf8::decode()ではなくEncode::decode_utf8()を使うべき理由
ãã¡ãã«ããã¨ãä¸æ£ãªUTF-8ã\x{fffd}ã§ç½®ãæãããããããã
ãã¨è¯ãè¦ãã1åç®ã®å¼æ°ãæ¸ãæããããå ´åãããããã ã(ãµãã«ã¼ãã³ã®ä¸ãã2è¡ç®)
ãã®è¾ºã®çç±ããªã¼æååãããã®ã¯ã
ã¨ããã®ãé ã«å
¥ãã¤ã¤ãä¸åº¦decode_utf8($str)ãdecode("utf8"=>$str)ã«ãããæååãããªããªã£ãã®ã§ãè¦ã¦ããã¨ããã¯åã£ã¦ããã®ã ã¨æãã
æéã«ä½è£ãããã¾ããªãã®ã§ãä»åã¯ããã§åãã¨ãã¦ããéãè¦ã¦decode_utf8()ã使ãã¹ãã ããªãã
åã¯ããæãã
ããã§ããã¼ã¸ã§ã³ä¸ããçµæã®ä¸å
·åããããããã ã£ãã
Perlã®å¾æ¹äºææ§ãããã