eval EXPR is capable of accessing lexicals.
my $t = 'test'; print eval '$t'; # test
As long as it can "see" them (i.e. As long as they are in scope)
my $t1 = 'test1'; sub show { print eval "\$$_" for @_; } my $t2 = 'test2'; show(qw( t1 t2 )); # test1, but not test2
It can't see a variable that no longer exists.
{ my $t = 'test'; sub show { print eval "\$$_" for @_; } } show(qw( t )); # Nothing
It can't see a variable that is no longer in scope.
{ my $t = 'test'; sub foo { $t } sub show { print eval "\$$_" for @_; } } show(qw( t )); # Nothing
...unless the function with the eval EXPR captured it.
{ my $t = 'test'; sub show { $t; print eval "\$$_" for @_; } } show(qw( t )); # test
Anyway, why aren't you passing the variable's value instead of its name?
In reply to Re: issues with eval (get a variable's value)
by ikegami
in thread issues with eval (get a variable's value)
by squale
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |