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

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

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
December 8, 2004 10:52
Subject:
Re: [perl #2215] redo undefines variables declared like while (my $i ...) { redo; }
Message ID:
20041208185510.GF2684@iabyn.com
On Wed, Dec 08, 2004 at 10:38:37AM -0000, Orton, Yves wrote:
> 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.

I'm with Yves on this one.

-- 
Thank God I'm an atheist.....

Thread Previous | 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