in reply to Re^2: Hex regex fails in subroutine
in thread Hex regex fails in subroutine
BTW, you can do all this in a single pass, if performance matters.
sub convert_to_html_entities { my $str= shift; utf8::decode($str); $str =~ s/[\x{201A}-\x{2122}]/ '&#'.ord($&).';' /ger; }
You could even just wholesale replace all non-ascii characters to completely sidestep the encoding problem:
sub convert_nonascii_to_html_entities { my $str= shift; utf8::decode($str); $str =~ s/[^\x20-\x7E]/ '&#'.ord($&).';' /ger; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Hex regex fails in subroutine
by AnomalousMonk (Archbishop) on Sep 30, 2023 at 13:40 UTC | |
by NERDVANA (Priest) on Sep 30, 2023 at 22:50 UTC |