Debugging a Perl Program

Debugging a Perl Program

It’s possible to start the debugger with a piece of Perl code as an argument by including the C<-e> switch on the command line. To debug a particular program instead, we substitute the program name to be debugged, along with any required arguments. So let’s do this with our current program (charcount) and dive into it with the debugger:

%> perl -d ./charcount ./charcount

Loading DB routines from perl5db.pl version 1.22
Editor support available.

Enter h or `h h’ for help, or `man perldebug’ for more help.

main::(./charcount:9): my $file = $ARGV[0] || ”;
DB<1>

Here we have stopped on the first runtime executable line of the code which,
from the information line given, can be seen to be line 9 of our file.

You can read more about this in the Pro-Perl-Debugging book.

LEAVE A COMMENT