On 31 July 2013 01:05, Father Chrysostomos via RT <perlbug-followup@perl.org> wrote: > 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. > IMO if you have to include eval "" in your sub then there is something else wrong too. I'm not saying this argues against closing the ticket, but right now it is not clear to me that it should be. Yves -- perl -Mre=debug -e "/just|another|perl|hacker/"Thread Previous | Thread Next