For short scripts, your example is equivalent to
which copies file* to outfile* (see perlrun). Use the -e switch to add further processing.perl -p -i'out*' file1 file2 file3
In bigger programs eof()
(note the missing parantheses) indicates
a change of $ARGV. You can use that to get rid of handling
$oldarg.
Update: Oops, corrected after ysth's comment. Thanks.
Update2: Clarification: The use of the -i (in-place edit) switch produces a
result that is equivalent to the given (OP) example only. If you add further processing (-e), the new output will be found in the files given at the command line (file1, file2, ...) but not in outfile1, outfile2, etc. since they are the backups of the original files. So, using 'out*' for the backup filename is generally a bad idea (ill. semantics). I should have made this more clear in the original answer.
In reply to Re: Changing the output filehandle while iterating input files.
by Perlbotics
in thread Changing the output filehandle while iterating input files.
by reedx032
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |