如何摆脱“印刷品中的宽字符"? [英] how to get rid of `Wide character in print at`?

查看:43
本文介绍了如何摆脱“印刷品中的宽字符"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件/tmp/xxx 具有下一个内容:

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 ...

来源是:

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

打印输出为:

кирилик  

推荐答案

您正在打印到不希望使用UTF8的STDOUT.添加

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

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

在已打开的手柄上更改它.

to change that on the already opened handle.

这篇关于如何摆脱“印刷品中的宽字符"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆