What are some good Perl debugging methods?

前端 未结 18 1005
南笙
南笙 2020-12-12 21:12

Are there other ways for debugging Perl programs apart from Data::Dumper and perl -d?

相关标签:
18条回答
  • 2020-12-12 21:52

    I like Devel::Trace. Basically it gives you an execution dump, showing you the code paths.

    On another side, test-driven development is all the rage now, so you could also be interested in profiling tools like Devel::NYTProf for highly advanced testing. See this Tim Bunce's blog post for an interesting overview.

    0 讨论(0)
  • 2020-12-12 21:56

    Available tools for debugging

    There are several tools available in Perl for debugging and similar tasks.


    Built-in command line debugger.

    perl -d yourcode.pl
    

    Devel::ptkdb

    Perl/Tk based graphical debugger by Andrew E. Page.


    Regex Coach

    This a free tool running both on Linux and Windows written in Lisp. Source code is not available.


    Rx: A Regex Debugger for Perl

    The Perl Regex debugger and an article about it written by Mark Jason Dominus.


    A GUI for the Perl Debugger

    0 讨论(0)
  • 2020-12-12 21:56

    My usual range of tools is:

    • print statements and Data::Dumper for simple cases
    • perl -d

    That's usually enough. There is ffffd; I heard it's quite nice, but never played with it.

    For some tasks (which are not really debugging, but close to it) I use Devel::NYTProf.

    0 讨论(0)
  • 2020-12-12 21:57

    I use ActiveState Komodo for step-by-step debugging.

    Eclipse has a step by step debugger for its EPIC plugin.

    Personally I prefer the ActiveState version. It just seems more solid and stable, but it does cost (and work is paying for me). If it was my money then I would use Eclipse and EPIC as these are free.

    0 讨论(0)
  • 2020-12-12 21:57

    The best debugging aids are small routines, short scopes, limited side effects, and lots of tests. Stop bugs before they hatch.

    0 讨论(0)
  • 2020-12-12 21:59

    During development, I like to embed printf statements in strategic places (not too many) which are enabled with a debug flag like this:

    printf("h='$h', j='$j', ... (%d)\n", __LINE__) if $debug;
    

    where the debug flag is defined at the top of the script:

    my $debug = $ENV{DEBUG} || 0;
    

    Now instead of having to remember to comment out all of the printf lines, I just run the script as follows:

    DEBUG=1 ./script.pl
    

    After testing when everything is ready for production, the debug lines can be removed:

    cat script.pl | grep -v 'if $debug;'
    
    0 讨论(0)
提交回复
热议问题