SPUG: "last" behaving oddly in -n loop

John W. Krahn krahnj at acm.org
Wed Aug 20 20:47:51 CDT 2003


On Wednesday 20 August 2003 17:36, Tim Maher/CONSULTIX wrote:
> On Wed, Aug 20, 2003 at 04:02:41PM -0700, John W. Krahn wrote:
> > > $ perl -wln last2 motd1 motd2
> > > 1: motd1
> > > File is motd1
> > > $
> > >
> > > Why didn't it process the second file, motd2, as happens with
> > > "next"? It's acting like last is magically allowed to break out
> > > of the outer (invisible) foreach loop, while next only affects
> > > the inner (invisible) while loop.
> >
> > next and last are working as designed.  There is no (invisible)
> > foreach loop.  <> processes the files in @ARGV as a continuous list
> > of lines.
>
> I know the diamond operator works that way, but according to the
> deparsing, it's *not* <> being used, but instead <ARGV>, which I
> was assuming to be populated by the result of an open (ARGV,
> shift), or something similar, in a surrounding (implicit) loop.

That may be a problem with B::Deparse.  :-)  <ARGV> and <> do exactly 
the same thing and if you use <> you will see that ARGV and $ARGV are 
in use.  B::Deparse outputs "LINE: while (defined($_ = <ARGV>)) {" but 
as anyone who has used perl for a while knows the "defined($_ =" part 
is redundant and is rarely (if ever) used in real Perl5 code so we can 
probably assume that B::Deparse is just being verbose for some reason.


John
-- 
use Perl;
program
fulfillment




More information about the spug-list mailing list