gpt4 book ai didi

perl - utf8::all -- 如何强制 为 big-5

转载 作者:行者123 更新时间:2023-12-02 07:46:40 24 4
gpt4 key购买 nike

这是我的测试代码:我正在使用 win32 草莓 perl。

use utf8::all; my $input = ;

当输入一个汉字时,

它显示错误:

utf8 "\xAD" does not map to unicode .....

我也用utf8::all写过一个脚本来打印汉字,没成功。如果只使用utf8或者不使用utf8,我都可以通过编码打印汉字。

如何设置为其他编码?

最佳答案

How to set the to other encoding?

使用utf8::all,你不能。编码 UTF-8 在其中的所有地方都是硬编码的。毕竟,该模块的名称是 utf8::all 而不是 big5::all

您必须显式解码/编码,参见http://p3rl.org/UNI .你说你在 Windows 上,所以使用编码 cp950 .

use Encode qw(decode encode);

my @arguments_as_characters = decode 'cp950', @ARGV;
open my $file_handle, '<:encoding(cp950)', $file_name;
print encode 'cp950', $data_to_stdout;


How to open STDIN, STDOUT in cp950?

当您运行您的程序时,标准流已经打开了!您可以修改 I/O layerbinmode .

binmode STDOUT, ':encoding(cp950)';

关于perl - utf8::all -- 如何强制 <STDIN/OUT> 为 big-5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6557934/

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