in reply to Re^23: search and replace strings in different files in a directory
in thread search and replace strings in different files in a directory
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, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^25: search and replace strings in different files in a directory
by PitifulProgrammer (Acolyte) on Sep 10, 2014 at 11:02 UTC | |
by PitifulProgrammer (Acolyte) on Sep 12, 2014 at 10:43 UTC | |
by Anonymous Monk on Sep 13, 2014 at 07:27 UTC | |
by PitifulProgrammer (Acolyte) on Sep 18, 2014 at 08:50 UTC | |
by PitifulProgrammer (Acolyte) on Oct 01, 2014 at 09:55 UTC |