作者garibaldi76 (贾宝迪)
看板Perl
标题Re: [心得] Windows下unicode的txt档案操作
时间Sun Aug 31 05:01:01 2008
刚刚再试了一下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
1F:→ garibaldi76:有人知道如何更优雅地处理BOM吗? 08/31 05:02
2F:→ JeffHung:为了优雅,势必要有些地方dirty。 08/31 13:47