perl中的转码问题
时间:2010-05-20 来源:fucj
1 #!/usr/bin/perl -w
2 use Encode;
3 open File,"<file";
4 while (<File>) {
5 $a=decode(utf8,$_); ======先解码,成为perl 能识别的字节流
6 print "$a\n========\n";
7 $b=encode(gb2312,$a); =======把字节流编码为gb2312格式,进行输出
8 print $b;
9 }
注:perl不能自动识别文本的编码方式,转码的时候需要先制定读入的编码方式,使之成为perl能接收的字节流,然后通过decode制定输出的编码方式,来实现转码
2 use Encode;
3 open File,"<file";
4 while (<File>) {
5 $a=decode(utf8,$_); ======先解码,成为perl 能识别的字节流
6 print "$a\n========\n";
7 $b=encode(gb2312,$a); =======把字节流编码为gb2312格式,进行输出
8 print $b;
9 }
注:perl不能自动识别文本的编码方式,转码的时候需要先制定读入的编码方式,使之成为perl能接收的字节流,然后通过decode制定输出的编码方式,来实现转码
相关阅读 更多 +
排行榜 更多 +