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

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

Thread Previous | Thread Next
From:
Steve Peters via RT
Date:
August 26, 2005 09:06
Subject:
[perl #7615] (if|unless) ( local ... ) not undone
Message ID:
rt-3.0.11-7615-119935.0.157128382309324@perl.org
> [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.


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