Re: [心得] Windows下unicode的txt檔案操作
剛剛再試了一下unicode轉big5, 結果發現對\r和BOM的處理會有問題, 所以要額
外將\r和BOM清掉...
open INPUT, '<:raw:encoding(UTF-16LE)', "unicode.txt" or die "input fail: $!";;
open OUTPUT, '>:encoding(big5)', "test.txt" or die "output fail: $!";
my $bom_is_removed = 0;
while(<INPUT>){
unless($bom_is_removed){
s/^\x{feff}//;
$bom_is_removed = 1;
}
s/\r$//;
print OUTPUT $_."----\n" ;
}
close OUTPUT;
close INPUT;
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.204.124.229
→
08/31 05:02, , 1F
08/31 05:02, 1F
→
08/31 13:47, , 2F
08/31 13:47, 2F
討論串 (同標題文章)