Perl: Passing Unicode string to chr()
I'm pretty new to Perl so pardon me for what will probably turn into a most obvious answer.
I'm trying to pass a Unicode markup to the chr()
function.
Here's a redacted example of my script.
#!/usr/bin/perl
$unicode = "/u0026amp;";
print chr("0x".substr($unicode, 4, 2))."\n";
This properly extracts the 26 from the $unicode variable.
However the problem as I can tell is that the chr()
function doesn't like quoted strings, but if I remove the quotes the x in 0x gets removed and becomes an invalid 026 rather than a valid 0x26.
Anyways, 开发者_开发百科this really gets down to. How can I keep the x in
chr("0x".substr($unicode, 4, 2))
from disappearing and send the proper 0x26
You do not use "0x" strings with chr
, the way you can with ord
and hex
. So you want:
chr(hex($hexstring))
精彩评论