Are there other ways for debugging Perl programs apart from Data::Dumper
and perl -d
?
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.
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
My usual range of tools is:
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.
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.
The best debugging aids are small routines, short scopes, limited side effects, and lots of tests. Stop bugs before they hatch.
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;'