jlandman has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
Is there an even cooler way to this?
Here I am reading the file keywords.txt. the format is:
filename minus extension \t keywords to add to file.the idea is to open the file (adding .xml) and inserting the keywords element at the 4th line.
Feels like I should be able to localize $^I and make use of the diamond operator to then edit each file in place.
perl -F'\t' -ane 'open (A, "$F[0].xml"); open(B, ">$F[0]") ;while(<F>) + { print B; if ($.==4) { print B " <keywords> ".substr($F[1],0,-1)." + </keywords>\n" ; }} close(A); close(B); unlink("$F[0].xml"); rename( +$F[0], "$F[0].xml");' keywords.txt
less is more!
thanks,
Josh
20050930 Janitored by Corion: Added formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: inline replace
by graff (Chancellor) on Sep 30, 2005 at 23:41 UTC |