#!/usr/bin/perl -w
use strict;
use Encode;
print packUcode('更换ab'),"\n";
#输出:\u66f4\u6362\u61\u62
print unpackUcode('\u66f4\u6362\u61\u62'),"\n";
#输出:更换ab
sub packUcode {
my $str=shift || return;
$str = encode('utf8', decode('gb2312',$str));
Encode::_utf8_on($str);
$str=~s/(\w)/sprintf(";
return $str;
}
sub unpackUcode {
my $str=shift || return;
$str =~ s/\\u([0-9a-fA-F]{2,4})/pack('U', hex($1))/eg;
Encode::_utf8_off($str);
$str = encode('gb2312', decode('utf8',$str));
return $str;
}
阅读(2954) | 评论(1) | 转发(0) |