I notice you have this:
while( <$infh> ) { s{&}{&}g; ## In some case does not match as intended s{&amp;}{&}g; ... }
presumably because, when the input line already contains &, the first substitution changes it to &amp;, so the second substitution is needed to change it back again! Better to replace these two substitutions with a single substitution using a negative look-ahead assertion (?!...). Proof-of-concept:
14:25 >perl -wE "my @s = ('Fred & Wilma', 'Barney & Betty'); for ( +@s) { s{&(?!amp;)}{&}g }; say for @s;" Fred & Wilma Barney & Betty 14:25 >
See “Look-Around Assertions” in perlre#Extended-Patterns.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^24: search and replace strings in different files in a directory
by Athanasius
in thread search and replace strings in different files in a directory
by PitifulProgrammer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |