On Tue Jul 30 12:33:33 2013, sprout wrote: > use PadWalker 'peek_my'; > use Data::Dumper; > use Scalar::Util 'weaken'; > > my @vars; > sub outer { > my ($var1, $var2, $var3); > push @vars, \$var1, \$var2, \$var3; > weaken $_ for @vars; > return sub { $var2; @vars; warn Dumper peek_my(0); } > } > > outer->() > __END__ > $VAR1 = { > '$var2' => \undef, > '@vars' => [ > undef, > $VAR1->{'$var2'}, > undef > ] > }; > > You see that two of the weak references in @vars have gone stale by the > time the closure is called. I don’t think it is worth changing how closures work for the sake of those cases where the outer sub is still running. In short: closures close over variables, not lexical scopes, unless string eval is involved. (So one can work around this by including eval "" in the sub.) I don’t think anything needs fixing here, so I am rejecting the ticket. -- Father Chrysostomos --- via perlbug: queue: perl5 status: open https://rt.perl.org:443/rt3/Ticket/Display.html?id=119049Thread Previous | Thread Next