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

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

Thread Next
From:
Orton, Yves
Date:
December 8, 2004 02:38
Subject:
RE: [perl #2215] redo undefines variables declared like while (my$i ...) { redo; }
Message ID:
E471ED2DFD9353458E8B75FD6D6B0307B638B8@defra1ex4.de.mcilink.com
Steve Peters wrote:
> This does not appear to be a bug.  Quoting "Programming Perl, Second
> Edition", "The redo command restarts the loop block without evaluating
> the conditional again."  So, when it re-enters the block, the shift is
> not performed and $i is implicitly defined to undef and the previous
> value is lost.  

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.

Cheers,
Yves

Thread Next


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