You prepend an underscore to your actual subroutine names, call them by their 'normal' names and have AUTOLOAD add the diagnostic prints and call the underscored versions.use strict; use vars q{$AUTOLOAD}; dostuff("One"); dostuff2("Two"); sub AUTOLOAD { no strict "refs"; print "Entering sub $AUTOLOAD.\n"; my $sub=join "::_", split /::/,$AUTOLOAD; &$sub(@_); print "Exiting sub $AUTOLOAD.\n"; } sub _dostuff { print "We're in dostuff: @_.\n"; } sub _dostuff2 { print "We're in dostuff2: @_.\n"; } __END__ Entering sub main::dostuff. We're in dostuff: One. Exiting sub main::dostuff. Entering sub main::dostuff2. We're in dostuff2: Two. Exiting sub main::dostuff2.
Note that, although this implementation works, it is probably not the most efficient, as the entire AUTOLOAD system is expensive. But it's the best I could come up with for now. Other people will probably come up with better ways (and probably have in the time it took me to type this :) ).
CU
Robartes-
In reply to Re: modifying sub routine behaviour
by robartes
in thread modifying sub routine behaviour
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |