develooper Front page | perl.perl5.porters | Postings from August 2005

Re: [perl #7615] (if|unless) ( local ... ) not undone

From:
Ronald J Kimball
Date:
August 26, 2005 09:17
Subject:
Re: [perl #7615] (if|unless) ( local ... ) not undone
Message ID:
20050826161742.GC81974@penkwe.pair.com
On Fri, Aug 26, 2005 at 09:06:50AM -0700, Steve Peters via RT wrote:
> > [bwarnock@capita.com - Mon Sep 03 10:43:30 2001]:
> > 
> > 
> > -----------------------------------------------------------------
> > Local variables declared in a conditional expression of a
> > conditional block are not restored at the end of scope.
> > 
> > $a = 10;
> > if (local $a = 1){
> > }
> > print $a; # Should be 10, not 1
> > 
> > Applies to local variables declared in 'if (expr)', 'unless(expr)',
> > and 'elsif (expr)'.  Lexical variables are okay, as are local
> > variables in the conditional expression of a loop block.
> > 
> 
> This behavior has been fixed in bleadperl by not allowing it.  
> 
> > ./perl rt_7615.pl
> Can't localize lexical variable $a at rt_7615.pl line 4.

$a isn't a lexical variable in the example, so that doesn't fix it.

Ronald



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