my $x = "\\347\\234\\213\\346\\235\\245";

my @octs = split /\\/, $x;

my @ints;

for my $oct (@octs) {
  $oct = "0" . $oct;
  push @ints, oct($oct);
}

my $str = "";
for my $int (@ints) {
  $str .= chr($int);
}

print $str, "\n";

在我的机器上测试输出成功。终端编码是utf-8.

在 2011年8月29日 下午3:10,Phillip Huang <[email protected]>写道:

> 各位,
>
> 我得到一组八进制转码的 UTF-8
>
>   \347\234\213\346\235\245\
>
> 请问有没有什么办法(perl脚本)将其转换为中文?
>
> PS: 我用了一个很笨的方法,在ubuntu的字符映射表中去查找(结果是“看来”二字)。
>
> 谢谢,
>
> ph
>
> --
> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
> 要取消订阅此网上论坛,请发送电子邮件至 [email protected]。
> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
>



-- 
---------------------------
Achilles Xu

-- 
您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
要向此网上论坛发帖,请发送电子邮件至 [email protected]。
要取消订阅此网上论坛,请发送电子邮件至 [email protected]。
若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。

回复