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
LINE: while (<>) {
...
}
I thought that meant it processes <STDIN>, not @ARGV, am I reading perlrun wrong or should
the code example read ...?
LINE: while (@ARGV) {
...
}