in reply to Re^4: Accessing lexicals in other scopes dynamically by name
in thread Accessing lexicals in other scopes dynamically by name
sub make_closure { my ($x) = @_; return sub { $x }; } my $c1 = make_closure("a"); my $c2 = make_closure("b"); say $c1->(); # a say $c2->(); # b
The $x from the first call to make_closure and the $x from the second call to make_closure are kept alive beyond the end of their normal scope (the end of that call to make_closure).
|
|---|