This section provides a debugging tutorial session to investigate a script by setting break points, stepping through each statement, printing variable values.
Here is the sample script that I used to practice Perl debugging commands:
Let's use the built-in debugger to find out why I am getting nothing for "Res 3".
Here is a recorded debugging session:
main::(DebugTest.pl:4): $res = &max(1.0, 0.5, 0.999999999999);
DB<1> l
4==> $res = &max(1.0, 0.5, 0.999999999999);
5: print "Res 1: ", $res, "\n";
6: $res = &max(0.999999999999);
7: print "Res 2: ", $res, "\n";
8: $res = &max();
9: print "Res 3: ", $res, "\n";
10: exit;
11 sub max {
12: my $max = shift(@_);
13: foreach $val (@_) {
DB<1> b 8
DB<2> s
main::max(DebugTest.pl:12): my $max = shift(@_);
DB<2> x @_
0 1
1 0.5
2 0.999999999999
DB<3> b
DB<3> c
Res 1: 1
main::max(DebugTest.pl:12): my $max = shift(@_);
DB<3> x @_
0 0.999999999999
DB<4> c
Res 2: 0.999999999999
main::(DebugTest.pl:8): $res = &max();
DB<4> s
main::max(DebugTest.pl:12): my $max = shift(@_);
DB<4> x @_
empty array
DB<5> n
main::max(DebugTest.pl:13): foreach $val (@_) {
DB<5> x $max
0 undef
DB<6> c
Res 3:
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
DB<6> q