in reply to large hash of regex substitution strings
(Please put your code in <c>...</c> tags. It'll handle escaping the necessary character and it'll place the line breaks for you.)
There's a lot of needless work here. Perl code and regexs are being parsed and compiled over and over again. Also, there's no reason to use /o anymore. It does nothing more than complicate things.
my %chartran = ( "\xE1" => 'aacute', "\xE2" => 'acirc', "\xE4" => 'auml', "\xC0" => 'Agrave', "\xC1" => 'Aacute', ); my $re = '[' . (join '', keys %chartran) . ']'; $re = qr/$re/; while (<VRUN>) { s/($re)/$chartran{$1}/g; print; }
Of course, you could simply use core module HTML::Entities's encode_entities method.
use HTML::Entities qw( encode_entities ); while (<VRUN>) { print encode_entities($_); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: large hash of regex substitution strings
by throop (Chaplain) on Oct 06, 2007 at 04:18 UTC | |
by ikegami (Patriarch) on Oct 06, 2007 at 04:54 UTC | |
|
Re^2: large hash of regex substitution strings
by scodes (Initiate) on Oct 07, 2007 at 04:47 UTC | |
by ikegami (Patriarch) on Oct 19, 2007 at 20:42 UTC | |
by Anonymous Monk on Oct 07, 2007 at 23:58 UTC |