in reply to Re^2: Accessing lexicals in other scopes dynamically by name
in thread Accessing lexicals in other scopes dynamically by name
the point is rather that at run time the variable doesn't exist any more in your example.
Exactly. And the reason it doesn't exist is because it wasn't captured. That would have kept it alive. You can see the capture increasing the ref count in the following snippet:
$ perl -MDevel::Peek -e' sub f { my $x; Dump($x); my @a = map { sub { $x } } 1..3; Dump($x); } f() ' SV = NULL(0x0) at 0x817bc90 REFCNT = 1 FLAGS = (PADMY) SV = NULL(0x0) at 0x817bc90 REFCNT = 4 FLAGS = (PADMY)
|
|---|