note
ikegami
Almost.
<ul>
<li>You forgot to convert the text to a regexp pattern.
<li>You only replace the first instance.
<li>And since I'm already changing the line, I'll remove the useless use of <c>map</c>.
</ul>
<c>
$text =~ s/\Q$_\E/$fixers{$_}/g
for keys %fixers;
</c>
<p>It could still be improved if it's going to be done repeatedly.
<c>
my ($re) = map qr/$_/,
join '|',
map quotemeta,
keys %fixers;
while (...) {
...
$text =~ s/$re/$fixers{$_}/g
for keys %fixers;
...
}
</c>
<p>Or even better for pre-5.10
<c>
use List::Regexp qw( );
my $re = List::Regexp->new()->list2re( keys %fixers );
while (...) {
...
$text =~ s/$re/$fixers{$_}/g
for keys %fixers;
...
}
</c>
718936
718941