perl脚本中对字符编码的支持

# 使perl程序支持utf8宽字符编码,不添加下面几行打印中文字符时将出现Wide character in print警告或错误。
use utf8;
binmode(STDIN, ':encoding(utf8)');
binmode(STDOUT, ':encoding(utf8)');
binmode(STDERR, ':encoding(utf8)');
perl脚本处理中文等字符时,有时从文件读出的数据为字节码,需要进行解码才能正确显示。使用Encode模块即可处理。
use Encode;
# $str1为从文件或数据库等方式存储的utf8编码数据中取出的数据
my $str0 = decode("utf8", $str1);

posted @ 2014-07-23 23:29  Bennnyzhao  阅读(244)  评论(0编辑  收藏  举报