免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4421 | 回复: 3
打印 上一主题 下一主题

装了Encode::HanExtra,仍提示gb18030为未知编码 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-08-23 11:48 |只看该作者 |倒序浏览
看了下Encode::HanExtra的说明,只要装了这模块,使用encode的时候,就能使用gb18030了。
为何我这依然提示
  1. Unknown encoding 'gb18030' at mb_gb18030.pl line 8
复制代码
我的代码:
  1. use Encode;
  2. use FileHandle;

  3. my $fh =FileHandle->new($ARGV[0]);
  4. while ( my $line=$fh->getline ) {
  5.         print encode("utf8",decode("gb18030",$line));
  6. }
  7. undef $fh;
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-08-23 14:40 |只看该作者
回复 1# perlnewbie


    use Encode::HanExtra;    #Explicitly

论坛徽章:
0
3 [报告]
发表于 2011-08-23 15:37 |只看该作者
这个懒就不偷了。

但转换GB18030字符为UTF8,出现错误了----------无法正常显示了。

论坛徽章:
0
4 [报告]
发表于 2011-08-24 08:13 |只看该作者
# print encode("utf8",decode("gb18030",$line));

binmode (STDOUT, ":utf8");

#decode("gb18030",$line) is already perl internal utf8, you are double-encoding them...

print encode("unicode",decode("gb18030",$line));
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP