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

Is this a closure bug?

Thread Next
From:
Robin Houston
Date:
December 19, 2001 06:25
Subject:
Is this a closure bug?
Message ID:
20011219142559.A20596@puffinry.freeserve.co.uk
{
  my $x = 'A';
  sub f { sub { $x++ }       }
  sub g { sub { $x++ } if $x }
}
my $F=f();
my $G=g();
print $F->(),$G->(),"," for 1..4;


The behaviour is certainly... surprising...

 .robin.

ps. From http://www.perlmonks.com/index.pl?node=115689

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