[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";

參考網頁

  1. No comments yet.

  1. No trackbacks yet.

return top

%d 位部落客按了讚: