[Perl]Big5/UTF-8 编码转换的模组
Big5 及 UTF-8 编码的转换方式有两种 (请先安装 Encode::compat 模组):
方式一
use Encode::compat; use Encode qw(from_to); my $string = "中文"; #Big5 转 UTF-8 from_to($string, 'big5', 'utf8'); print "$string\n"; #UTF-8 转 Big5 from_to($string, 'utf8', 'big5'); print "$string\n";
方式二
use Encode::compat; use Encode qw(encode decode); my $string = "中文"; #Big5 转 UTF-8 my $utf8 = encode('utf8', decode('big5', $string)); print "$utf8\n"; my $big5 = encode('big5', decode('utf8', $utf8)); print "$big5\n";
No comments yet.