看板 Perl 關於我們 聯絡資訊
剛剛再試了一下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
garibaldi76:有人知道如何更優雅地處理BOM嗎? 08/31 05:02
JeffHung:為了優雅,勢必要有些地方dirty。 08/31 13:47