views:

279

answers:

4

I have some unicode codepoints (\u5315\u4e03\u58ec\u4e8c\u4e0a\u53b6\u4e4b), which I have to convert into actual characters they represent.

What's the simplest way to do so?

Thank you.

+1  A: 

Could Unicode::Escape be what you need?

izb
A: 
use JSON::XS
print JSON::XS->new->decode('{"a":"\u5315\u4e03\u58ec\u4e8c\u4e0a\u53b6\u4e4b"}')->{a}
Андрей Костенко
Tried exactly what you suggested, but unfortunately it didn't give me any output...
Peterim
A: 
perl -CO -le'print"\x{5315}\x{4e03}\x{58ec}\x{4e8c}\x{4e0a}\x{53b6}\x{4e4b}"'
Hynek -Pichi- Vychodil
A: 

Sometimes I'd just use pack:

binmode STDOUT, ':utf8';

my $string = '\\u5315\\u4e03\\u58ec\\u4e8c\\u4e0a\\u53b6\\u4e4b';

$string =~ s/\\u(....)/ pack 'U*', hex($1) /eg;

print $string;
brian d foy