in reply to Re: Accessing lexicals in other scopes dynamically by name
in thread Accessing lexicals in other scopes dynamically by name
Note: Subs only capture variables it knows it will need.I don't think that is true.
My understanding is that closures capture the whole environment (in the sense of lexical variable bindings).
Otherwise this would not be possible:
use strict; my $a = 1; my $b = 2; my $c = 3; sub f { my $var = shift; print $var, "=", eval "\$$var", "\n"; }; &f("a"); &f("b"); &f("c"); # prints a=1 b=2 c=3
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Accessing lexicals in other scopes dynamically by name
by ikegami (Patriarch) on Jul 30, 2010 at 16:59 UTC | |
by morgon (Priest) on Jul 30, 2010 at 17:48 UTC | |
by ikegami (Patriarch) on Jul 30, 2010 at 20:13 UTC | |
by morgon (Priest) on Jul 30, 2010 at 20:36 UTC | |
by ikegami (Patriarch) on Jul 30, 2010 at 22:20 UTC | |
|