in reply to nested routines, anonymous routines and location dependency
Note that named subroutine declarations are always evaluated before any code that call them, so the location is "irrelevant", which also means that there aren't any situations where you "must keep the location" of the declaration.sub print_power_of_2 { my $x = shift; my $power_of_2 = sub { return $x ** 2; }; my $result = $power_of_2->(); print "$x^2 = $result\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: nested routines, anonymous routines and location dependency
by Anonymous Monk on Mar 04, 2008 at 23:08 UTC | |
by Joost (Canon) on Mar 04, 2008 at 23:18 UTC | |
by Anonymous Monk on Mar 04, 2008 at 23:25 UTC | |
by chromatic (Archbishop) on Mar 04, 2008 at 23:40 UTC | |
by QM (Parson) on Mar 06, 2008 at 14:17 UTC | |
by ikegami (Patriarch) on Mar 04, 2008 at 23:42 UTC | |
by ysth (Canon) on Mar 05, 2008 at 02:32 UTC |