Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Tweaking 'return'.

by robin (Chaplain)
on Nov 23, 2005 at 12:05 UTC ( #511061=note: print w/ replies, xml ) Need Help??

in reply to Tweaking 'return'.

If you want to track entry and exit to all subroutines, the easiest way is to write a custom debugger. It's actually very easy:

# This is the custom debugger: { package DB; sub DB {} sub sub { print STDERR "== Entering sub $sub\n"; &$sub; # Call the sub print STDERR "=== Leaving sub $sub\n"; } } # Now some example code to test it with: sub hello { print "Hello, "; world(); } sub world { print "World!\n"; } $|++; # Turn off buffering, to make the control flow clearer hello();
The debugging code will only be activated if you run with perl -d, so:
$ perl Hello, World! $ perl -d Loading DB routines from version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. == Entering sub main::hello Hello, == Entering sub main::world World! === Leaving sub main::world === Leaving sub main::hello
See perldebguts for all the gory details.

Update: As a (probably better) alternative to running perl -d, you can use

BEGIN {$^P = 1}
to enable subroutine-tracing. That way you don't need the empty sub DB either. But woe betide you if you should actually run with perl -d. Maybe it's best to use something like
BEGIN { return if $^P; # If the debugger is running, leave well alone $^P = 1; # Enable subroutine tracing package DB; *sub = sub { print STDERR "== Entering sub $sub\n"; &$sub; print STDERR "=== Leaving sub $sub\n"; }; }

Comment on Re: Tweaking 'return'.
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://511061]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2015-11-27 13:52 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (729 votes), past polls