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, \©In);
if (!doIt) { return; }
if ($debuglevel > 1) {
# RIGHT HERE, how do I print the name of the subroutine?
}
&$sub(); # execute the subroutine
}
dispatch(1, \©In);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry, I was tired:
sub dispatch {
my ($doIt, $sub) = @_;
the question still stands.
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)?
see
perldoc perlsub