Eily has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks. I was using perl to translate files from one format to another with something like the following: perl -p > file.out when I got lazy and decided that I should be able to just pass a list of input files, and let perl append .out (or replace the extension) to create an output file for each input file.

There are obviously more than one way to do it and I settled for:

for my $filename (@ARGV) { open my $input, '<', $filename or die "Couldn't open $filename: $!"; open my $output, '>', $filename.'.new' or die "Couldn't open $filena +me: $!"; while (<$input>) { say $output translate($_); } }

Now I'm wondering, is there some simpler way to do it? This looks like a pretty common task, and it is very close to what -i does, except the two files are swapped: I want the output in the file with the added extension and the original unchanged. There doesn't seem to be an option for it, so do you know of some hack (bring out your secret operators, I'm asking out of curiosity so I want even the bad answers :D ) or some module that would let me write my code without having to write the explicit while(<>) loop on the data?

NB: yup I already just asked that in the CB and got some answers. Like choroba's proposition to call the file inside a shell loop to handle the output files.

Edit: perl -pE "open STDOUT, '>>', qq<$ARGV.txt>; s/(.*)/\U$1/;" FILES works once :P (inspired by choroba's proposition)