On Thu, Aug 1, 2013 at 1:35 AM, Ricardo SIGNES via RT <perlbug-followup@perl.org> wrote: > On Tue Jul 30 16:05:09 2013, sprout wrote: >> 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.) > > When did this become true in practice? > > It does not match up with what I take to be common definition of closures as enclosing a > complete environment. I agree that PadWalker is letting Perl programmers go beyond the realm > of polite behavior, but let's put that aside. > > Why shouldn't this program be able to print 2? > > use 5.12.0; > use PadWalker 'peek_my'; > > my $x = 1; > > use Data::Dumper; > > my $z = sub { > warn Dumper(peek_my(1)); > eval { ${ peek_my(1)->{'$x'} } = 2 } > }; > > my $w = sub { $z->() }; > > $w->(); > > say $x; > > What are the practical wins to making closure per-variable instead of per-environment? See also #89544 LeonThread Previous | Thread Next