in reply to Global matching not working as expected
Depending on how line-oriented your XML is, that regular expression might find none, one or all matches.
See perlre on "greedy" - .* will match as much as possible, including an intervening </Last-Modified> tag if possible.
There are two approaches to fixing this. The easy approach is to read the whole file into memory and do the replacement directly:
perl -0777 -le 's!<Last-Modified>(.*?)</Last-Modified>!<Last-Modified> +`date ...`</Last-Modified>!ge' mydoc.xml
The saner way is to use one of the XML parsing modules, for example XML::Twig.
Also, I would look at Time::Piece or Time::Local for doing the time conversion instead of shelling out to the date program for every replacement.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Global matching not working as expected
by BillKSmith (Monsignor) on Mar 19, 2016 at 13:51 UTC | |
|
Re^2: Global matching not working as expected
by ForeverLearning (Novice) on Mar 20, 2016 at 12:45 UTC |