in reply to Reading multiple files one line at a time from arguments
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reading multiple files one line at a time from arguments
by choroba (Cardinal) on Jun 19, 2014 at 08:06 UTC | |
by davido (Cardinal) on Jun 19, 2014 at 08:14 UTC | |
by choroba (Cardinal) on Jun 19, 2014 at 08:18 UTC | |
by davido (Cardinal) on Jun 19, 2014 at 08:40 UTC |