我正在尝试在UTF-8中的Perl中创建/保存HTML文件,但是到目前为止我什么都没做。 previous answer here on SO表示要使用binmode,所以我尝试了。这是我的代码:
open (OUT, ">$sectionfilename");
binmode(OUT, ":utf8");
print OUT $section;
close OUT;
当我在类似记事本的文本编辑器中打开这些文件时,它们仍为ANSI编码。我究竟做错了什么?
最佳答案
文本编辑器是检查低级内容(例如编码)的不良工具。请改用hexviewer / hexdumper。编写示例的现代方法:
use autodie qw(:all);
open my $out, '>:encoding(UTF-8)', $sectionfilename;
print {$out} $section;
close $out;
autodie启用自动错误检查。
关于perl - 如何从Perl将文件另存为UTF-8?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2339750/