Can I suggest a result that is wrong? Easy to verify: replace the loop code as follows:
my $counter; while ( $string =~ /(\X)/g ) { say ++$counter, ': ', $1; }
... and see how many times the regular expression matches. I think he will still match only once.
Alternatively, you can use this code:
use Encode; sub codepoint_hex { sprintf "%04x", ord Encode::decode("UTF-8", shift); }
... and then print codepoint_hex ($ 1) instead of just $ 1 inside the while loop.
raina77ow
source share