这是我的测试代码: 我使用的是win32草莓perl。utf8 :: all - 如何强制<STDIN/OUT>转换为big-5
use utf8::all; my $input = ;
当钥匙在中国性格,
它显示了错误:
utf8 "\xAD" does not map to unicode .....
我还写有UTF8脚本::所有打印中国字符,不能成功。 如果只使用utf8或不使用utf8,我可以通过编码来打印中文字符。
如何设置为其他编码?
这是我的测试代码: 我使用的是win32草莓perl。utf8 :: all - 如何强制<STDIN/OUT>转换为big-5
use utf8::all; my $input = ;
当钥匙在中国性格,
它显示了错误:
utf8 "\xAD" does not map to unicode .....
我还写有UTF8脚本::所有打印中国字符,不能成功。 如果只使用utf8或不使用utf8,我可以通过编码来打印中文字符。
如何设置为其他编码?
有一种解决方法可将Windows命令提示符的代码页设置为UTF-8,但它不是可部署的解决方案。
我的建议是不要打扰,只需在Perl中使用Big5(并且坚持使用CP950/zh-tw Windows),或者使用文本文件I/O进行输入/输出。
或者,冒险,使用cgywin中的bash/perl,而不是使用UTF-8。
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?
当你运行你的程序,标准流是已经打开!您可以使用binmode
修改I/O layer。
binmode STDOUT, ':encoding(cp950)';
use open IO => ':encoding(big5)';
或
use open IO => ':encoding(cp950)';
或
use open IO => ':locale';
如何CP950开STDIN,STDOUT? – Weiyan