String literal "\u6b63" creates the string 6b63 (since \u uppercases the next character). To create the string \u6b63, you need to use string literal "\\u6b63".
You can't interpolate into the middle of an escape sequence (like "\x{$_}"). Interpolation and escapes occur at the same level.
You're passing the hex representation of a number to chr, but chr expects a number. You can use hex to do the conversion.
$_ doesn't contain the hex number of the character as you'd need in the escape sequence. It contains the decoded character already (as returned by chr).
use open ':std', ':locale'; # So stuff you print shows up right. $_ = "\\u6b63"; print "orig string length is ", length($_), "\n"; print "orig string is $_\n"; s/\\u(.{4})/chr(hex($1))/eg; print "decoded string length is ", length($_), "\n"; print "decoded string is $_\n";
orig string length is 6 orig string is \u6b63 decoded string length is 1 decoded string is 正
Update: Added lots
In reply to Re^3: unicode/utf string to actual character
by ikegami
in thread unicode/utf string to actual character
by xachen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |