in reply to Open multiple file handles?
Perl has an operator that does what you're asking for. It's the diamond operator, and when used 'empty', it reads each item listed in @ARGV sequentially. See perlop. Here's a snippet from the documentation:
The null filehandle <> is special: it can be used to emulate the behavior of sed and awk. Input from <> comes either from standard input, or from each file listed on the command line. Here's how it works: the first time <> is evaluated, the @ARGV array is checked, and if it is empty, $ARGV[0] is set to "-", which when opened gives you standard input. The @ARGV array is then processed as a list of filenames. The loop
while (<>) { ... # code for each line }is equivalent to the following Perl-like pseudo code:
unshift(@ARGV, '-') unless @ARGV; while ($ARGV = shift) { open(ARGV, $ARGV); while (<ARGV>) { ... # code for each line } }
Dave
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Open multiple file handles?
by onlyIDleft (Scribe) on May 07, 2011 at 04:05 UTC | |
by davido (Cardinal) on May 07, 2011 at 05:39 UTC | |
by John M. Dlugosz (Monsignor) on May 07, 2011 at 07:20 UTC | |
by shaitand (Initiate) on Jan 30, 2013 at 18:35 UTC |
In Section
Seekers of Perl Wisdom