Don't ask to ask, just ask | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hello monks. I was using perl to translate files from one format to another with something like the following: perl -p translation.pl file.in > 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:
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 translation.pl 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) In reply to One to one file output idiom by Eily
|
|