|
|
|
Clear questions and runnable code get the best and fastest answer |
|
| PerlMonks |
Re: Hex regex fails in subroutineby BillKSmith (Monsignor) |
| on Oct 06, 2023 at 03:34 UTC ( [id://11154835]=note: print w/replies, xml ) | Need Help?? |
|
After much study, I determined that what your program does to a file is
replace non-ascii characters with their html equivalents. Your hex
sequences suggest that the external file is encoded as utf8, but you
read it as a string of bytes.
It has already been shown that your approach can be made to work. I prefer the following approach because its purpose is obvious. It lets perl decode the utf8 so it can substitute characters rather than byte strings. Note that all characters are treated the same. It does not matter how many bytes they require. Note also that the hash keys are the actual characters. The code point notation is just a convenient way to specify them without needing utf8 in the Perl code.
UPDATE: Removed use utf8 from code per hippo's comment.
Bill
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||||