免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4732 | 回复: 1

perl6 请教 win10下中文输入输出报错乱码 [复制链接]

论坛徽章:
0
发表于 2018-11-01 14:22 |显示全部楼层
本帖最后由 Linux_ren 于 2018-11-01 22:35 编辑

perl6 在win10系统下,无法读取和输出中文,不知道如何处理,谢谢。(改成utf8输出乱码,另外,在win下使用的话,utf8有诸多不便)

---------------1-------------------
use v6;
my $inifile = open '中文.txt';
for $inifile.lines -> $line {
    my @wards = split /\s+/, $line;
    say @wards[0];
}

错误提示:
Error while reading from file: Malformed UTF-8
-------------------2------------------------

use v6;
my $inifile = open 'cn.txt';  #cn.txt中有中文字符
for $inifile.lines -> $line {
    my @wards = split /\s+/, $line;
    say @wards[0];
}

错误提示
Malformed UTF-8
  in block <unit> at .\X.pl line 6
--------------------------------------------------------------------------------------------
刚刚在debian9下测试了一下,没有任何问题。win10下用的是最近的Rakudo Star 2018.06版本。而我在单位上正常是在windows上使用(我本职工作不是码农),原因不明,还请指教。

论坛徽章:
0
发表于 2018-11-13 23:57 |显示全部楼层
  1. use utf8;
  2. use Encode qw/encode decode/;

  3. my $name = encode("gb2312","中文.txt");

  4. open(ARRAYMARK,"<:encoding(utf8)",$name);
  5. while(my $line = <ARRAYMARK>)
  6. {       
  7.        
  8.         print $line;
  9. }

  10. print "ok!\n";
复制代码

我没有用perl6,这个代码是win10下可以运行的。
该代码和要读入的txt文件都使用utf8格式。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP