2007/05/06

Perl 5.8 PerlIO feature

With the new PerlIO feature and Unicode support in Perl 5.8, it is possible to do the internal encoding change with only a few lines of code.

Please check the code below. It will be able to read the GBK input from STDIN and convert it to UTF-8 to STDOUT. :)


#!/usr/bin/perl -W

use encoding "gbk", STDOUT => "utf8";
while(<>){print};


Power and Simple. :D

1 条评论:

linuxyz 说...

最近才看到, 其实还有更简单的方法:
perl -Mencoding=euc-cn,STDOUT,utf8 -pe1 < file.euc-cn > file.utf8

BlockChain 相关电子书

@copyright of Sam Chadwick   - https://thehub.thomsonreuters.com/groups/bitcoin/blog/2017/09/10/blockchain-paper Blockchain Papers A c...