sorry I don't understand this argumentation, if you want to make a symderef on a lexical you can always use eval
Not if a closure didn't include that variable:
use strict; use warnings; my $sub = do { my $x = 4; my $y = 5; sub { my $a = shift; print 'Accessing $x: ', $x + $a, "\n"; print 'Accessing $y from eval: ', eval '$y + $a', "\n"; }; }; $sub->(2); __END__ Accessing $x: 6 Use of uninitialized value in addition (+) at (eval 1) line 1. Accessing $y from eval: 2
Whoops. Perl knows at compile time which lexicals in outer scopes are needed for a closure, and only stores those.
With the current current behaviour only eval can be used to detect that. That's OK because eval has the "evil, don't use" stigma on it.
If symbolic deref would also look in lexicals, every deref might break this optimization.
I hope it's a bit clearer now.
In reply to Re^5: Indirect variable name
by moritz
in thread Indirect variable name
by FreakyGreenLeaky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |