Well I'm not certain what exactly you're looking for. They are closely related to references so something like this:
Is the same as:my $bar = sub { # do something here }; $bar->(); # executes the stuff in the anonymous sub above
sub foo { # do something here } my $bar = \&foo; $bar->(); #executes the stuff in foo()
I like to use a dispatch table in web apps that uses either anonymous subs or sub references. Like so:
my %actions = ( foo => \&do_foo, # some long operation bar => sub { # some short one line thing }, default => sub { # do something by default }, ); my $request = $cgi->param('request'); if( exists($actions{ $request } )) { $actions{ $request }->(); } else { $actions{ default }->(); }
Hope that gives you an idea of what's going on.
In reply to Re: Anonymous Subroutines
by cfreak
in thread Anonymous Subroutines
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |