develooper Front page | perl.perl5.porters | Postings from December 2004

RE: [perl #2215] redo undefines variables declared like while (my$i ...) { redo; }

From:
Orton, Yves
Date:
December 8, 2004 11:00
Subject:
RE: [perl #2215] redo undefines variables declared like while (my$i ...) { redo; }
Message ID:
E471ED2DFD9353458E8B75FD6D6B0307B638C1@defra1ex4.de.mcilink.com
Dave Mitchell wrote:
> > If your interpretation of this is correct then I think the documentation
> > should be changed to clarify the point. I wouldn't have expected this
result
> > from that description. In fact that description makes me think that
> > 
> >   my @a=(2..5);
> >   while (my $x=shift @a) {
> >       print $x,"\n";
> >       redo if $x--;
> >    }
> > 
> > and
> > 
> >   my @a=(2..5);
> >   while (my $x=shift @a) {
> > 	STARTBLOCK:
> >       print $x,"\n";
> >       goto STARTBLOCK if $x--;
> >    }
> > 
> > should be equivelent, but by your reading they aren't.
> 
> I'm with Yves on this one.

It occurred to me that there is another reason to not agree with the
proposed interpretation. It means that redo in for loops and while loops do
different things:

  my @a=(2..5);
  for my $x (@a) {
    print $x,"\n";
    redo if $x--;
  }

In this case the $x doesn't suddenly become undef after the redo.... 

IMO the reported bug is indeed a bug. 

Cheers,
Yves




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About