Hello Perl Monks,
This might seem as a trivial question but I plan to read one line at a time from files I would pass as argument on the command line to my script.
The following approach works for me:
#!/usr/bin/perl use strict; use warnings; for my $file(@ARGV) { open my $fh, "<", "$file" or die "Cannot open file: $!"; while (my $line = <$fh>) { print "$file: $line"; } }
I was wondering if this is the correct approach. Can you please suggest any other approaches? For some reason using a while loop inside for loop didn't seem idiomatic to me but I may be wrong as I am still learning to script with perl. For learning purposes I would appreciate if some one can suggest a more concise approach (even if it comes at the cost of readability).
Looking forward to your wisdom
Regards
Jaypal
UPDATE: Thanks everyone for all the different approaches.
In reply to Reading multiple files one line at a time from arguments by jaypal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |