[comp.lang.perl] Is <ARGV> equivalent to <>?

wwf@doe.carleton.ca (W. Walter Fergusson) (10/15/90)

I was having problems with a perl script reading in all the files when
only one was explicitly read in.  Here is a small script that mimics
the behavior.

#!/usr/local/bin/perl 
#
# taken from perl info page. (Thank you Jeff!)
unshift(@ARGV, '-') if $#ARGV < $[;
$ARGV = shift;
open(ARGV, $ARGV);
print ("processing file ", $ARGV, ".\n");
while (<ARGV>) {
	print;
}

This script will read from _ALL_ the files on the command line!  In fact
the script will work without the first three lines.

To me this suggests that the construct <ARGV> is identical to <> (at least
in a while statement).  The info page (derived from the man page) mentions
all the behind the sceen things that occur when <> is used but it implies
that the program above will not read from all files.

From the info page:
-----------------------------------------------------
...  The loop

     while (<>) {
             ...                 # code for each line
     }

   is equivalent to

     unshift(@ARGV, '-') if $#ARGV < $[;
     while ($ARGV = shift) {
             open(ARGV, $ARGV);
             while (<ARGV>) {
                     ...         # code for each line
             }
     }
-----------------------------------------------------

In fact the "while ($ARGV = shift) {" is completely unnecessary.

So if (<> == <ARGV>) then the documentation is confusing (or wrong), or
else there is a bug in the perl executable.


Particulars:

Running Perl 3.0@28, on Sun3s and Sun4s; SunOS 4.0.3.


Thanks for any help or clarification,
Walter Fergusson.

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (10/16/90)

Yes, <> and <ARGV> are the same thing.  The equivalent code given in the
manual page isn't real Perl code, but a very Perlish pseudo-code in which
ARGV doesn't have a special meaning.

Larry