develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24250] "return" required in some anonymous closures

From:
Elizabeth Mattijsen
Date:
October 20, 2003 03:18
Subject:
Re: [perl #24250] "return" required in some anonymous closures
Message ID:
p05111b02bbb9660f66a1@[192.168.56.2]
(I should stop answering my own posts  ;-)

At 11:55 +0200 10/20/03, Elizabeth Mattijsen wrote:
>Hmmm... both of the following return correct results also:

The problem can be simplified to the following code:

my $foo = 'foo';
my $get = sub () {$foo};
my $set = sub ($) {$foo = $_[0]};
$set->('bar');
print "foo = $foo = ".$get->()."\n";
__END__
foo = bar = foo


so this looks like an optimizer problem to me: the $get sub is 
referring to something else than the package lexical $foo.


Liz



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