jepri has asked for the wisdom of the Perl Monks concerning the following question:
I have been trying to write a one shot regexp that would trawl through the entire document and convert the hex codes back into the characters, but this code is the best I can come up with.
Can anyone see a better way to do it?
while ( my ( $hex ) = ($line =~ m/\[0x(..?)\]/)) { my $chr = pack("h*", $hex); #print "$line \n Found hex value '$hex', equals char $chr\n"; $line =~ s/\[0x$hex\]/$chr/; }
____________________
Jeremy
I didn't believe in evil until I dated it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looking for regexp to convert hex numbers in text
by rob_au (Abbot) on Nov 06, 2001 at 18:11 UTC | |
|
Re: Looking for regexp to convert hex numbers in text
by busunsl (Vicar) on Nov 06, 2001 at 18:13 UTC | |
by Hofmator (Curate) on Nov 07, 2001 at 16:40 UTC | |
|
Re: Looking for regexp to convert hex numbers in text
by Zaxo (Archbishop) on Nov 06, 2001 at 18:21 UTC | |
|
Re: Looking for regexp to convert hex numbers in text
by staeryatz (Monk) on Nov 07, 2001 at 02:08 UTC |