Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

perl option to trace execution

by Anonymous Monk
on Jan 05, 2005 at 16:41 UTC ( [id://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.

Thanks.

Replies are listed 'Best First'.
Re: perl option
by Fletch (Bishop) 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 script.pl

    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 script.pl.

    More info here: http://search.cpan.org/~aepage/Devel-ptkdb-1.1091/ptkdb.pm
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!


      Mike
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
    watson-wilson.ca

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 foo.pl", 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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://419653]
Approved by gellyfish
Front-paged by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2024-04-18 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found