[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.