develooper Front page | perl.perl5.porters | Postings from July 2013

[perl #119049] referencing some variables hides others from PadWalker starting 5.17.2

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
July 30, 2013 23:05
Subject:
[perl #119049] referencing some variables hides others from PadWalker starting 5.17.2
Message ID:
rt-3.6.HEAD-2552-1375225509-167.119049-15-0@perl.org
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=119049

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