"Perl for Perl Newbies" - Part 2Using the perl DebuggerStepping over and Stepping in

11.1. Stepping over and Stepping in

The debugger displays the perl statement that is about to be executed in its display window, and below it the command prompt. It looks something like this:

shlomi:~/bin# perl -d add_cr.pl
Default die handler restored.

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

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

main::(add_cr.pl:5):	my ($contents);
  DB<1>

The most commonly used command in the debugger is to have it execute one (and only one) perl statement. This is called stepping and there are two types of it: stepping over and stepping in.

The difference is that stepping over does not enter the perl functions that were called in the expression that was evaluated. Stepping in, on the other hand, does enter such functions.

To step over type n (short for "next") followed by enter , and you'll see the next perl command displayed. To step in type s (short for "step").

And here's how the screen will look after a few step overs:

shlomi:~/bin# perl -d add_cr.pl test.txt
Default die handler restored.

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

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

main::(add_cr.pl:5):	my ($contents);
  DB<1> n
main::(add_cr.pl:7):	foreach my $file (@ARGV)
main::(add_cr.pl:8):	{
  DB<1> n
main::(add_cr.pl:9):	    $contents = "";
  DB<1> n
main::(add_cr.pl:11):	    open my $in, "<", $file;
  DB<1>

Note that sometimes an expression will take more than one step over to pass. Operations such as map, sort and friends are especially notorious for that. Breakpoints that will be covered in the next slide offer a solution to this problem.


Written by Shlomi Fish