how to get rid of `Wide character in print at`?

混江龙づ霸主 提交于 2021-02-07 13:24:32

问题


I have file /tmp/xxx with next content:

00000000 D0 BA D0 B8 │ D1 80 D0 B8 │ D0 BB D0 B8 │ D0 BA     к и р и л и к

When I read content of file and print it I get the error:

Wide character in print at ...

The source is:

use utf8;
open my $fh, '<:encoding(UTF-8)', '/tmp/xxx';
print scalar <$fh>

The output from print is:

кирилик  

回答1:


You're printing to STDOUT which isn't expecting UTF8. Add

binmode(STDOUT, "encoding(UTF-8)");

to change that on the already opened handle.




回答2:


The use utf8 means Perl expects your source code to be UTF-8.

The open pragma can change the encoding of the standard filehandles:

use open qw(:std :utf8);


来源:https://stackoverflow.com/questions/47940662/how-to-get-rid-of-wide-character-in-print-at

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!