gpt4 book ai didi

perl - 如何从 Perl 将文件另存为 UTF-8?

转载 作者:行者123 更新时间:2023-12-03 07:39:04 25 4
gpt4 key购买 nike

我正在尝试在 Perl 中以 UTF-8 创建/保存 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com