in reply to Re: Iterative anonymous subroutines
in thread Iterative anonymous subroutines
The error occurs because the my hasn't occured at the time where $anon is used. (Assignments are processed right to left.)Not exactly; the problem isn't the run-time effect of my not having occurred, it's with the compile-time effect.
my() "returns" (not exactly, since it's a declarator, not a function) the new lexical and that "returned" SV can be used in the current statement, but for purposes of compiling other mentions of the lexical of that name, the lexical's scope only begins with the following statement.
This can be seen with
perl -we'$foo = 2; print((my $foo=4),$foo)' </c> printing 42, not 44.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Iterative anonymous subroutines
by duff (Parson) on Dec 14, 2005 at 00:45 UTC |