Hi there,
I am trying to translate some old perl 5 code and I am having trouble with a
particular line.
I used to have this in perl 5 to translate multibyte encoding like "%C3%A1":
$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex($1))/eg;
And I have translated the regex to something like this:
$value ~~
s:g/[\%(<[\dA..Fa..f]><[\dA..Fa..f]>)]+/{pack(............).decode()}/;
So I thought I could just change the base of the matching hex bytes and pack
them, but the pack function is not working as it did in perl 5.
I tried many things and the closest solution I came to implied using the
"template" argument of the pack function like this:
print pack("CC", 195, 161).decode();
This produces the character "รก".
As you can see, I am adding as many "C"s as bytes there be. And I can count the
elements in the regex match to construct the template, but I'm wondering if
there is a better approach.
All of your comments on the matter would be much appreciated.
Kind Regards,
Emiliano