Link to home
Start Free TrialLog in
Avatar of dbkruger
dbkruger

asked on

how to write a subroutine that takes a subroutine as a parameter, executes it, but prints out the name

sub dispatch($doIt, $sub) {
  if (!doIt) { return; }
  if ($debuglevel > 1) {
# RIGHT HERE, how do I print the name of the subroutine?
  }
  &$sub(); # execute the subroutine
}



dispatch(1, \&copyIn);
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sub dispatch($doIt, $sub) { is not the proper syntax for subroutine prototypes
see
perldoc perlsub
Avatar of dbkruger
dbkruger

ASKER

sorry, I was tired:

sub dispatch {
  my ($doIt, $sub) = @_;

the question still stands.
How about the built-in function "caller" (see http://perldoc.perl.org/functions/caller.html)?  Or a module on CPAN, like the DB module (http://search.cpan.org/dist/perl/lib/DB.pm) or Hook::LexWrap (http://search.cpan.org/dist/Hook-LexWrap/lib/Hook/LexWrap.pm)?