muncher has asked for the wisdom of the Perl Monks concerning the following question:

Is there an easy way when calling a subroutine to determine what called that subroutine? This is for debugging purposes so I don't have to put print statements all through the code.

ie. subroutine A calls subroutine B, What can I do in B to know that A called B?

Also, can anyone recommend a perl graphical debugger (something like DDD is on my wish list) that works?

Thanks

M

Replies are listed 'Best First'.
Re: subroutine tracking
by broquaint (Abbot) on Jun 25, 2002 at 10:00 UTC
    Is there an easy way when calling a subroutine to determine what called that subroutine?
    There sure is and it's called caller().
    sub foo { print "calling bar()", $/; bar(); } sub bar { print "in bar()", $/; print "called by - ", (caller(1))[3], $/; } foo(); __output__ calling bar() in bar() called by - main::foo
    Check out the caller() docs for more info on this funky little function.
    HTH

    _________
    broquaint

Re: subroutine tracking
by bronto (Priest) on Jun 25, 2002 at 11:29 UTC

    Take a look at the caller function.

    About a graphical debugger, I use ptkdb; it's a visual debugger written in Perl/Tk by Andrew Page. I can't remeber if the PDF documentation is part of the package, but it exists if you need it, and it's very good. You can install it with <code>perl -MCPAN -e 'install Devel::ptkdb'.

    Ciao!
    --bronto

      If you are on Windows ptkdb is also available for ActivePerl. Just do a ppm install Devel-ptkdb
      Then you can run it with perl -d:ptkdb myscript.pl

      --

      flounder

Re: subroutine tracking
by Joost (Canon) on Jun 25, 2002 at 10:20 UTC
    Also, can anyone recommend a perl graphical debugger (something like DDD is on my wish list) that works?

    Have you tried ddd --debugger perl ?

    --
    Joost - continually stating the obvious.

Re: subroutine tracking
by zejames (Hermit) on Jun 25, 2002 at 10:02 UTC
    caller is what you are looking for... Nothing graphical here although ...


    HTH


    --
    zejames
Re: subroutine tracking
by Jenda (Abbot) on Jun 25, 2002 at 20:30 UTC