"Perl for Perl Newbies" - Part 2Using the perl DebuggerSetting Breakpoints and Continuing

11.2. Setting Breakpoints and Continuing

When the user places a breakpoint on a certain line in a program, they instruct the debugger to stop the execution of the program when this line is reached. Then, one can cause the program to run freely using the continue command, and have it stop only at this line.

Breakpoints generally save a lot of stepping. To set a breakpoint type b $line_number or b $function_name where $line_number is the line number and $function_name is the function name. A breakpoint on a function will stop the execution of the program as soon as the function is entered.

To continue the execution of the program until a breakpoint is reached (or until the program terminates) type c. Here is an example session with the same program:

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> b 11
  DB<2> c
main::(add_cr.pl:11):	    open my $in, "<", $file;

One can set a conditional breakpoint by typing b [line] [perl expression]. A conditional expression is one that stops the execution of the program only if the perl expression evaluates to true. The perl expression can be as complex as you like and may include whitespace.

To delete a breakpoint type d [line]. After a breakpoint is deleted it will no longer affect the execution of your program.

Written by Shlomi Fish