I want the perl program launch debugger when some condition hit. Some other language has debug() statement supported by library, is there any similar statement in perl?
If I understand you correctly, you need to use a specific debugger variable in your code - $DB::single
. Setting this to a true value in your code will cause the debugger to stop on that line.
$x = 1234;
$DB::single = 1;
enter_problematic_sub_now();
Your code will then stop at the line with $DB::single set to 1.
Of course, if you can't actually ensure that your code is running in the debugger then you have another problem entirely. You will need to run your code via perl -d
as well.
Essentially the
-d
switch allows you to communicate with the perl executable, and allows the perl executable to communicate with you.
More
Have you tried adding the -d switch to the shebang line at the top of your script? Something like
#!/usr/bin/perl -d
use strict;
use warnings;
$|=1;$\="\n";
print "Test";
It really depends exactly how it gets launched, but at least in simple cases this should start the debugger.
Edit: You can then set a breakpoint on a specific line with a certain condition using
> b [line] [condition]
and hit
> c
to continue with running the script - the debugger will stop at the specified line when the condition is met
Well, there is something which will enable you to do something like breakpoints, but the functionality is wider: Perl Debugger.