in reply to Re^2: Accessing lexicals in other scopes dynamically by name
in thread Accessing lexicals in other scopes dynamically by name
Nothing's captured. $a, $b, $c are still in scope, and we've already established that eval should and can access lexicals in scope.
Place all by the calls to f() in curlies or in a module and you'll see it doesn't capture.
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");
$ perl -w a.pl Variable "$a" is not available at (eval 1) line 2. Use of uninitialized value in print at a.pl line 11. a= Variable "$b" is not available at (eval 2) line 2. Use of uninitialized value in print at a.pl line 11. b= Variable "$c" is not available at (eval 3) line 2. Use of uninitialized value in print at a.pl line 11. c=
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Accessing lexicals in other scopes dynamically by name
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 | |
by morgon (Priest) on Jul 30, 2010 at 22:37 UTC | |
|