in reply to How do closures and variable scope (my,our,local) interact in perl?
One can even combine it with loop-var-aliasing!
lanx$ perl -e ' $a='a';$b='b'; my $var; for $var ( $a,$b ) { *$var=sub {print "$var \n" } };$var="x"; a();$b="y";b(); ' a y lanx$ perl -e ' $a='a';$b='b'; for $var ( $a,$b ) { *$var=sub {print "$var \n" } };$var="x"; a();$b="y";b(); ' x x
Obfuscators, here we are! ;-)
Well seriously, I think as a rule of thumb you discovered, that a "localised" lexvar my $var;for $var(){} has the same "closuring"-effects like a for my $var () {} .
I bet they act exactly the same...
Cheers Rolf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do closures and variable scope (my,our,local) interact in perl?
by ikegami (Patriarch) on Jun 16, 2009 at 18:23 UTC |