in reply to Changing the output filehandle while iterating input files.

For short scripts, your example is equivalent to

perl -p -i'out*' file1 file2 file3
which copies file* to outfile* (see perlrun). Use the -e switch to add further processing.

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.

Replies are listed 'Best First'.
Re^2: Changing the output filehandle while iterating input files.
by ysth (Canon) on Sep 21, 2008 at 10:35 UTC
Re^2: Changing the output filehandle while iterating input files.
by betterworld (Curate) on Sep 21, 2008 at 10:52 UTC

    In your example, "out*" will be the original file, while in the OP's code, "out*" will be the new file. Otherwise they are equivalent.

    Update: And please note that errors are not checked in either case. Imho a big problem with the "-p" switch is that it does not check whether writing and closing is successful.