If you didn't care about what file name you're processing, the entire script could look like this:
die "Usage: mytest filename [filename [...]]\n" unless @ARGV; print while <>;
...because (see perlop) the <> operator shifts filenames off of @ARGV and opens them internally. If @ARGV starts out empty, it reads from STDIN instead.
Here's another approach that is quite similar to yours, but borrows the idea of shifting filenames out of @ARGV:
die "Usage: mytest filename [filename [...]]\n" unless @ARGV; while( my $file = shift ) { open my $ifh, '<', $file or die $!; print "$file($.): $_" while <$ifh>; }
Dave
In reply to Re: Reading multiple files one line at a time from arguments
by davido
in thread Reading multiple files one line at a time from arguments
by jaypal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |