We introduced the standard Perl debugger in Intermediate Perl so we could examine complex data structures. It’s well documented in the perldebug, and Richard Foley devoted an entire book, Pro Perl Debugging (Apress), to it, so I will only cover enough of the basics here so I can move on to the fancier debuggers.
I invoke the Perl debugger with Perl’s -d switch:
perl -d add_number.pl 5 6
Perl compiles the program, but stops before running the statements, giving me a prompt. The debugger shows me the program name, line number, and the next statement it will execute:
Loading DB routines from perl5db.pl version 1.25 Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(Scripts/debugging/add_numbers.pl:3): 3: my $n = shift @ARGV; D<1>
From there I can do the usual debugging things, such as single-stepping through code, setting breakpoints, and examining the program state.
I can also run the debugger on a program I specify on the command line with the -e. I still get the debugger prompt, but it’s not very useful for debugging a program. Instead, I have access to the debugger prompt where I can try Perl statements:
$ perl -d -e 0
Loading DB routines from perl5db.pl version 1.25 Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(-e:1): 0 D<1> $n = 1 + 2;
D<2> x $n 0 3 D<3>
We showed this debugger in Intermediate Perl, and it’s well documented in perldebug and many other tutorials, so I won’t spend time on it here. Check the references in the last section in this chapter, “Further Reading ,” for sources of more information.