blazar has asked for the wisdom of the Perl Monks concerning the following question:
Basically I have this small sized script which accepts a list of filenames on the cmd line. The first file should be processed differently from the other ones (which as usual may be substituted by STDIN).
One obvious approach could be
But I'm keen on iterating on ARGV and I was thinking of#!/usr/bin/perl use strict; use warnings; die "Usage: $0 <file> [<files>]\n" unless @ARGV; open my $fh, '<', shift or die $!; while (<$fh>) { # ... } while (<>) { # ... } __END__
too. (Of course the latter has the disadvantage of doing an additional check at each iteration.)while (<>) { # ... last if eof(ARGV); } while (<>) { # ... }
Now it would be nice if there was an ARGV variant allowing one to iterate on the FH associated to the current $ARGV only, but since there is none available AFAIK, how would you do it?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How would you do it? Re ARGV, fundamentally!
by merlyn (Sage) on Jul 19, 2005 at 11:38 UTC | |
by blazar (Canon) on Jul 19, 2005 at 11:47 UTC | |
by merlyn (Sage) on Jul 19, 2005 at 11:58 UTC | |
|
Re: How would you do it? Re ARGV, fundamentally!
by inman (Curate) on Jul 19, 2005 at 11:36 UTC | |
|
Re: How would you do it? Re ARGV, fundamentally!
by holli (Abbot) on Jul 19, 2005 at 10:39 UTC | |
by blazar (Canon) on Jul 19, 2005 at 10:44 UTC |