Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

perl option to trace execution

by Anonymous Monk
on Jan 05, 2005 at 16:41 UTC ( #419653=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

Is there an option I can turn on which can show me which lines in my perl files are being processed...My perl script is not doing what it should and I don't want to put print statements all over the place.


Replies are listed 'Best First'.
Re: perl option
by Fletch (Chancellor) on Jan 05, 2005 at 16:43 UTC

    Try installing Devel::Trace and then use perl -d:Trace foo. That'll get you something similar to a shell's set -x functionality.

      I just want to pipe up briefly in support of Devel::Trace. It has a much lower learning curve than most of the other suggestions and does precisely what Anonymous Monk asked for.
      the -d:Trace can go on a shebang line too.
Re: perl option
by qq (Hermit) on Jan 05, 2005 at 16:43 UTC
Re: perl option
by Popcorn Dave (Abbot) on Jan 05, 2005 at 17:03 UTC
    You may want to try the Graphical Debugger. It's written in Perl/Tk and has saved my bacon numerous times.

    You can watch your variables as your program executes - which is what I assume you wanted to do with the print statements you don't want to liberally sprinkle all across your program. The really nice thing is that you can also contract or expand arrays, hashes and complex data structures so you can see how they're being modified.

    Good luck!

    Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.
Re: perl option
by hubb0r (Pilgrim) on Jan 05, 2005 at 20:24 UTC
    perl -d

    Takes a little learning to use the debugger.

    There's a graphical debugger addon that I've recently been using that's (in my opinion) very useful, and fairly stable. Its Devel::ptkdb and is invoked via perl -d:ptkdb

    More info here:
Re: perl option
by techra (Pilgrim) on Jan 05, 2005 at 22:12 UTC

    There's also a couple of other ways I've always found to be helpful in debugging perl scripts, especially since I mostly work in a web environment.

    Setting a scalar (say $debug) to 1 or 0 at function call and having your print functions conditional on $debug being true.

    ( print "I'm here" if $debug ). Better yet, writing your own debug function that listens to some higher-level variable is also a great way to do it.

    I also recommend the very nifty Smart::Comments from CPAN, which allows you to use specially formated # comments based on conditions, printed to the buffer.

      I think you mean Smart::Comments (using the cpan:// syntax). There's no Smart::Comments node on perlmonks.

      BTW, thanks for the pointer, that's an interesting looking module!

Re: perl option
by neilwatson (Priest) on Jan 05, 2005 at 19:44 UTC
    Never underestimate the use of print and die statements. They are simple but valuable during development.

    Neil Watson

Re: perl option to trace execution
by mkirank (Chaplain) on Jan 06, 2005 at 05:51 UTC
Re: perl option to trace execution
by DigitalKitty (Parson) on Jan 06, 2005 at 18:01 UTC
Re: perl option to trace execution
by Anonymous Monk on May 12, 2016 at 01:44 UTC
    Use the debugger's autotrace setting. "perl -d", then at the debugger prompt, turn on auto trace "o AutoTrace=1". "c" to continue program execution and it will show each line as it is executed.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://419653]
Approved by gellyfish
Front-paged by ikegami
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2018-01-22 14:30 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (233 votes). Check out past polls.