A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Perl debugger tutorial

If you've never used the Perl debugger before, it is pretty easy when you know how:

1) Add this special breakpoint statement to your script, where you want it to stop so you can look around:
$DB::single = 1;

2) Run the script with -d like this:
perl -d myscript.pl

The script will stop at the first line of code. Press 'c' to continue on to the first breakpoint.

Basic commands:
n = next line (step over any subs)
s = next line (step into any subs)
c = continue

one more command:
v = view lines

There's a trick to make it do 'v' at every step, type this once:
{{v

Instructions:
Step through the script using either 's' or 'n' and make sure it's doing what you think it's doing.

You might get into some gnarly library code at some point. In that case you'll have to either:
a) endure it and keep stepping through until you reach your code on the other side
or
b) set a breakpoint a bit later on, then restart the debugger and keep pressing 'c' until you reach the right place

The difference between 's' and 'n' is, when executing any subroutine call:
- 'n' steps over the subroutine (runs it) and carries on
- 's' steps into the subroutine and you can step through the code inside it

Finally:
You can type any perl statement at the debugger prompt to see what values the variables and things have, for example:
use Data::Dumper;
print Dumper($foo);

Other commands:
q = quit
h = help

See also perldoc perldebug and perldoc perldebtut.

--
Thanks to Nour for being a guinea pig.