免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: 兰花仙子

Windows中文 - 编码!编码!! [复制链接]

论坛徽章:
0
发表于 2011-02-19 16:57 |显示全部楼层
本帖最后由 FenRagwort 于 2011-02-19 16:59 编辑

回复 10# yakczh


    前三行不要这样写

而是写成这样
  1. use utf8;
  2. use open ':encoding(gbk)', ':std';
  3. use open ':encoding(utf8)';
复制代码
从命令行给的参数,文件如果是utf8的就这么写,如果是gbk的,第三行可以不要

论坛徽章:
0
发表于 2011-02-19 17:36 |显示全部楼层
终端utf8环境,文件utf8编码,

  1. use utf8;
  2. use open ':encoding(gbk)', ':std';
  3. use open ':encoding(utf8)';
复制代码
运行 perl  u8.pl  中文
输出结果 


----------stdin-----------

"\x{00e4}" does not map to cp936 at u8.pl line 20.
"\x{00b8}" does not map to cp936 at u8.pl line 20.
"\x{00e6}" does not map to cp936 at u8.pl line 20.
"\x{0096}" does not map to cp936 at u8.pl line 20.
"\x{0087}" does not map to cp936 at u8.pl line 20.
string:\x{00e4}\x{00b8}-\x{00e6}\x{0096}\x{0087}
bytes:e4       b8      ad      e6      96      87
----------code -----------

string:

         utf8 "\xD6" does not map to Unicode at u8.pl line 35.
utf8 "\xD0" does not map to Unicode at u8.pl line 35.
utf8 "\xCE" does not map to Unicode at u8.pl line 35.
utf8 "\xD3" does not map to Unicode at u8.pl line 35.
utf8 "\xCE" does not map to Unicode at u8.pl line 35.
utf8 "\xFE" does not map to Unicode at u8.pl line 35.
utf8 "\xB6" does not map to Unicode at u8.pl line 35.
utf8 "\xC1" does not map to Unicode at u8.pl line 35.
utf8 "\xC8" does not map to Unicode at u8.pl line 35.
bytes:4e2d     6587
----------io -----------

"\x{0134}" does not map to cp936 at u8.pl line 20.
"\x{013c}" does not map to cp936 at u8.pl line 20.
string:\xD6\xD0\xCE\x{0134}\xD3\xCE\x{013c}\xFE\xB6\xC1\xC8
bytes:5c       78      44      36      5c      78      44

论坛徽章:
0
发表于 2011-02-19 17:46 |显示全部楼层
本帖最后由 yakczh 于 2011-02-19 20:07 编辑

use utf8;
#use open ':std';
use open ':encoding(gbk)';

这样就可以, use utf8 对页面编码,标准输入都起作用

但是终端gbk环境下,还是没解决办法 
环境是cp936,页面是gbk,读utf8文件,读命令行参数(即测试stdin)

论坛徽章:
0
发表于 2011-02-19 18:58 |显示全部楼层
本帖最后由 yakczh 于 2011-02-19 19:09 编辑

就终端环境,页面编码,IO编码三种环境分gbk,utf8两种编码,共8种组合,做了个简单的测试
结果如图 t_019.jpg

论坛徽章:
0
发表于 2011-02-19 19:11 |显示全部楼层
刚测试了一下,windows命令行读入UTF-8编码的文本,并print到终端,如下两种方式都可以:

  1. use encoding "utf8", STDOUT => 'gbk';
  2. open HD,"<:encoding(UTF-8)","data.txt";
复制代码


以及:

  1. use open ':encoding(GBK)', ':std';
  2. use open ':encoding(UTF-8)';
  3. open HD,"data.txt";
复制代码


TTDLTLM *

(中国版的TMTOWTDI,条条大路通罗马)

论坛徽章:
0
发表于 2011-02-19 20:00 |显示全部楼层
回复 15# 兰花仙子
perl gbk-read-u8.pl     中文 


print $ARGV[0];

这个参数可以正常显示吗?

论坛徽章:
0
发表于 2011-02-19 22:19 |显示全部楼层
终端不要用UTF-8编码,会有bug
从这里看下去
http://www.newsmth.net/bbstcon.p ... 458&start=57508

论坛徽章:
0
发表于 2011-02-19 22:54 |显示全部楼层
终端是用登两个shell,一个export LANG=zh_CN.UTF-8  另一个是用export LANG=zh_CN.GBK

论坛徽章:
0
发表于 2011-02-20 09:18 |显示全部楼层
本帖最后由 yakczh 于 2011-02-20 09:21 编辑

更新一下测试结果,除了STDIN=>xxx 不起作用,需要用Encode特殊处理一下,基本解决了在IO层处理编码问题
out-0.jpg

论坛徽章:
1
双子座
日期:2013-11-06 17:18:01
发表于 2011-03-25 16:55 |显示全部楼层
就终端环境,页面编码,IO编码三种环境分gbk,utf8两种编码,共8种组合,做了个简单的测试
结果如图
yakczh 发表于 2011-02-19 18:58



    页面编码是什么,是perl脚本的保存编码吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP