Perl Print Win32 Console Windows 控制台 print Unicode 问题

参考资料:

https://stackoverflow.com/questions/15224400/perl-on-windows-problems-with-encoding

https://technet.microsoft.com/en-us/library/bb490874.aspx

http://blog.csdn.net/xiezechang/article/details/8544292

问题:

1 use utf8;
2 
3 print "中文";

输出是乱码.

解决办法:

CMD 输入命令 chcp, 得到的数字, 比如: 936

然后代码改为如下:

1 use utf8;
2 use open ':std', ':encoding(cp936)';
3 
4 print "何来";

有意思的是, 如果你直接从控制台输入中文, 再直接 print, 不会乱码. 代码如下

use utf8;

$text = <STDIN>;  # 输入 "中文"

print $text; # 不需要任何额外的其他东西就能正常输出

BTW, 我用的 Strawberry Perl