use 5.6.0; use Jcode; # Windowsでは、Jcode.pmをインストールすると、NoXSバージョンと呼ばれる # Perlネイティブモードで処理されるバージョンがインストールされますが、 # これはとても遅いです。 use utf8; # utf8モジュールを使用している時に、日本語文字にダブルクォートやqq//を使うと # 以下のようなメッセージが出ます。 # Malformed UTF-8 character at xxx line xx. my $string = 'あいう'; print "code=", scalar Jcode::getcode(\$string), "\n"; print "length=", length($string), "\n"; print 'あいう=> ', $string, "\n"; @string = split //, $string; for $str ( @string ){ print $str,":\n"; } print "-----\n"; #$j = Jcode->new($string, scalar Jcode::getcode(\$string)); #$utf8_str = $j->utf8; $utf8_str = 'あいう'; Jcode::convert(\$utf8_str, 'utf8','sjis'); print "code=", scalar Jcode::getcode(\$utf8_str), "\n"; print 'あいう=> ', $utf8_str, "\n"; print "length=", length($utf8_str), "\n"; @utf8_str = split //, $utf8_str; for $u_str ( @utf8_str ){ $sjis_str = Jcode->new($u_str, 'utf8')->sjis; print $sjis_str,":\n"; } print "-----\n"; # 文字列が日本語文字と英字混合だと判定がおかしい。 # utf8と判定 $utf8_str1 = 'あいうえお'; Jcode::convert(\$utf8_str1, 'utf8','sjis'); print '$utf8_str1= あいうえお: code=', scalar Jcode::getcode(\$utf8_str1), "\n"; # sjisと判定 $utf8_str2 = 'あいうABC'; Jcode::convert(\$utf8_str2, 'utf8','sjis'); print '\$utf8_str2 = あいうABC: code=', scalar Jcode::getcode(\$utf8_str2), "\n";