Why would I use Perl anonymous subroutines instead of a named one?
I'm just curious why one would choose to use an anonymous subroutine, versus a named one, in Perl. Thanks. innaM You can store anonymous subs in arrays, hashes and scalars. You can build them at runtime You can pass them as arguments to other functions. You get to keep variables in the surrounding scope. The last point is probably the most important, because it's often the most unexpected facet of named vs. anonymous subroutines in Perl. Example: sub outer { my $a = 123; sub inner { print $a, "\n"; } # At this point, $a is 123, so this call should always print 123, right? inner(); $a = 456; }