P is for Practical | |
PerlMonks |
-i switch behaviourby fireartist (Chaplain) |
on Jun 18, 2004 at 13:25 UTC ( [id://367934]=perlquestion: print w/replies, xml ) | Need Help?? |
fireartist has asked for the wisdom of the Perl Monks concerning the following question:
I'm been experimenting with the command line switch -i. I was confused with results at first, but I think I'm starting to figure it out. I have a file "testfile" that contains the text "testdata". When I run ls testfile | perl -lpi -e 's/e/*/' I get the output "t*stfil*" and the file contents are unchanged. However, if I run ls testfile | xargs perl -lpi -e 's/e/*/' There is no output to STDOUT, and the contents of the textfile are changed as expected, now reading "t*stdata". It took me a while to figure out what was happening, but it seems that files are only edited in place when the filenames are passed as arguments, not as STDIN. This was confirmed when I found merlyn's post xargs functionality for inplace editing which uses find ... -print | perl -pi.bak -e 'BEGIN { chomp(@ARGV = <STDIN>) } s/foo/bar/g' However, perlrun -i "specifies that files processed by the <> construct are to be edited in-place" The code explaination also reads I thought that meant it processes <STDIN>, not @ARGV, am I reading perlrun wrong or should the code example read ...?
Back to
Seekers of Perl Wisdom
|
|