in reply to How to search and replace text characters in a perl script
Here's one example, kind of following along the code layout you already have. In the 'E' case, we simply attempt a regex substitution (s//;), and for the 'Z' entries, we check if we have a match first, capture the match into two parts ($1, $2), and if there is a match, we do the substitution:
while (<>) { chomp; # EN.NNNNN # no need for if(), we're not using the capture number vars s/E\d\.\d{5}//; # ZNN.NNN # need if, or it'll warn on no match if (/G1 Z\d{1,2}\.\d{3}/){ s/(G1 Z)(\d{1,2}\.\d{3})/$1-$2/; } print "$_\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to search and replace text characters in a perl script
by AnomalousMonk (Archbishop) on May 20, 2016 at 06:11 UTC | |
|
Re^2: How to search and replace text characters in a perl script
by thetekguy (Initiate) on May 20, 2016 at 03:14 UTC |