use strict; #this is variable holding a ref to an anon sub my $mysub1 = sub { print "mysub1 called\n" }; #this is a regular subroutine sub mysub2 { print "mysub2 called\n"; } #call this with a refrerence to an array sub references sub take_subs { my @arrayofsubs= @{$_[0]}; print "take_subs called, now calling each subref\n"; foreach (@arrayofsubs) { &$_; } } # call take_subs with each type take_subs ([ $mysub1, # variable holding anon sub reference \&mysub2, # sub reference sub { print "anonymous sub called\n" } #anon sub ]); __OUTPUT__ take_subs called, now calling each subref mysub1 called mysub2 called anonymous sub called
--
flounder
In reply to Re: subs as args
by flounder99
in thread subs as args
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |