Consider this small perl program, test.pl :
#!/usr/bin/env perl use warnings; use strict; use Number::Format qw(:subs); # sudo perl -MCPAN -e 'install Number::Format' my $tstr = ""; my $numFormatter = new Number::Format(); for (my $ix=0; $ix<20; $ix++) { $tstr = $tstr . int(rand(10)); my $ftstr = $numFormatter->format_number($tstr, 2, 1); print "ix: $ix ; in: $tstr ; out: $ftstr\n"; }
If I run it, it will fail. If I run it in the Perl debugger using perl -d , it will also fail with an error:
$ perl -d test.pl Loading DB routines from perl5db.pl version 1.39_10 Editor support available. Enter h or 'hh' for help, or 'man perldebug' for more help. main::(test.pl:6): my $tstr = ""; DB<1> c ix: 0 ; in: 6 ; out: 6.00 ix: 1 ; in: 63 ; out: 63.00 ix: 2 ; in: 637 ; out: 637.00 ix: 3 ; in: 6379 ; out: 6,379.00 ix: 4 ; in: 63790 ; out: 63,790.00 ix: 5 ; in: 637906 ; out: 637,906.00 ix: 6 ; in: 6379062 ; out: 6,379,062.00 ix: 7 ; in: 63790624 ; out: 63,790,624.00 ix: 8 ; in: 637906246 ; out: 637,906,246.00 ix: 9 ; in: 6379062467 ; out: 6,379,062,467.00 ix: 10 ; in: 63790624671 ; out: 63,790,624,671.00 ix: 11 ; in: 637906246715 ; out: 637,906,246,715.00 ix: 12 ; in: 6379062467152 ; out: 6,379,062,467,152.00 ix: 13 ; in: 63790624671522 ; out: 63,790,624,671,522.00 round() overflow. Try smaller precision or use Math::BigFloat at test.pl line 11. at /usr/local/share/perl/5.18.2/Number/Format.pm line 535. Number::Format::round('Number::Format=HASH(0x9d0b6cc)', 637906246715226, 2) called at /usr/local/share/perl/5.18.2/Number/Format.pm line 601 Number::Format::format_number('Number::Format=HASH(0x9d0b6cc)', 637906246715226, 2, 1) called at test.pl line 11 Debugged program terminated. Use q to quit or R to restart, use o inhibit_exit to avoid stopping after program termination, hq, h R or ho to get additional info. DB<1> p $ix DB<2>
... but when it fails, it does not stop on the line of failure, as gdb with program C says, maybe the program terminates again, and therefore I have no context variables to check.
Of course, such a cycle can be performed thousands of times, so setting a breakpoint in the problem line and executing c ontinue manually will not help here ...
Is there a way for the Perl debugger to crash the program on error / exception, so that the context of the local variable is saved to check the variables there?