次のような文字列があります。
Why RUNAS Windows \xee\x80\x80\x45xplorer\xee\x80\x81 Doesn\xe2\x80\x99t
Work After Installing IE7 St\xc3\xa5le
XML ファイルを読み取って取得します。これは UTF-8 文字列です。次に、同等の Unicode 文字を出力して、次のようにします。
Why RUNAS Windows Explorer Doesn’t Work After Installing IE7 Ståle
私は小さなプログラムを試しました:
use strict;
use utf8;
use Encode;
my $str = "Why RUNAS Windows \xee\x80\x80\x45xplorer\xee\x80\x81 Doesn\xe2\x80\x99t Work After Installing IE7 St\xc3\xa5le";
print $str;
そしてそれは働いた!!
問題は、ファイルから文字列を読み込もうとしているときに変換されないことです。したがって、以下は unicode 出力を生成しません。
use strict;
use utf8;
use Encode;
my $str = <DATA>;
$str = decode("utf8", $str);
open OUT, ">", "o.txt" or die;
binmode(OUT,":utf8");
print OUT $str;
__DATA__
Why RUNAS Windows \xee\x80\x80\x45xplorer\xee\x80\x81 Doesn\xe2\x80\x99t Work After Installing IE7 St\xc3\xa5le