encode_utf8
$octets = encode_utf8($string);
相当于 $octets = encode("utf8", $string).
这个字符串在$string 是被编码成Perl的内部格式, 结果是返回 a sequence of octets.
8位字节的顺序
decode_utf8
$string = decode_utf8($octets [, CHECK]);
相当于 $string = decode("utf8", $octets [, CHECK]).
the sequence of octets
8位字节的顺序 通过$octets 是被解码从UTF-8 到一个逻辑字符的顺序
[oracle@oadb utf-8]$ cat a1.pl
use Encode;
my $str="测试更健康";
print length($str);
print "
";
print $str."
";
[oracle@oadb utf-8]$ perl a1.pl
15
测试更健康
[oracle@oadb utf-8]$ cat a1.pl
use Encode;
my $str="测试更健康";
$str=encode_utf8($str);
print length($str);
print "
";
print $str."
";
[oracle@oadb utf-8]$ perl a1.pl
30
æµè¯æ´å¥åº·
[oracle@oadb utf-8]$
[oracle@oadb utf-8]$ cat a1.pl
use Encode;
my $str="测试更健康";
$str=decode_utf8($str);
print length($str);
print "
";
print $str."
";
[oracle@oadb utf-8]$ perl a1.pl
5
Wide character in print at a1.pl line 6.
测试更健康