in reply to Iterative anonymous subroutines
The proper word is recursive, not iterative. Iterative means something else.
The error occurs because the my hasn't occured at the time where $anon is used. (Assignments are processed right to left.) Therefore, the sub uses the package variable $main::anon. Cause the my to occur first by seperating the my from the assignment:
my $anon; $anon = sub { my $count = shift; if ($count--) { print "Iterating\n"; $anon->($count); } }; $anon->(4);
Update: Elaborated on the problem.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Iterative anonymous subroutines
by diotalevi (Canon) on Dec 13, 2005 at 18:55 UTC | |
by ikegami (Patriarch) on Dec 13, 2005 at 19:20 UTC | |
|
Re^2: Iterative anonymous subroutines
by ysth (Canon) on Dec 13, 2005 at 19:56 UTC | |
by duff (Parson) on Dec 14, 2005 at 00:45 UTC |