Newsgroups: comp.lang.perl
Path: utzoo!utgpu!cunews!alfred.ccs.carleton.ca!wwf
From: wwf@doe.carleton.ca (W. Walter Fergusson)
Subject: Is <ARGV> equivalent to <>?
Message-ID: <WWF.90Oct15165051@data.doe.carleton.ca>
Summary: The perl man page is inconsistent with the perl executable regarding
Sender: news@ccs.carleton.ca (news)
Organization: Carleton University, Electronics Department.
Distribution: comp
Date: 15 Oct 90 16:50:51
the construct <ARGV>.

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.
