$DB::single = 1 : Make that debugger stop where you want it
February 18, 2012 1 Comment
Sometimes it’s useful to get a perl debugger to stop exactly where you want it to stop.
When debugging on the command line I’ve got a relatively manual process of bringing up a debugger, use-ing my module of choice if it’s not already loaded, breaking at a method name, continuing, then breaking at the line I want. It’s likely there is a better way to do this, but I haven’t found it yet because I usually just insert a
$DB::single = 1;
expression exactly where I want it.
I’m sure most people know about this, but if you don’t, take a look at
$ perldocĀ perldebug
and pay attention to the section describing
$DB::single = 1;
Inserting that expression will make the perl debugger stop on that line when it’s reached. You can just fire up your program or test case in the debugger and let it run.
Also useful could be wrapping that statement in a condition that checks for your particular case or iteration.
The perl debugger is filled with other great magic, but I find $DB::single is a feature I use often.
Like many, I’ve used the Perl debugger for years and never come across this. I guess until something really starts annoying you you don’t necessarily read all the pod for something and so this has passed me by. Thanks for pointing it out. A link to the item discussed is Debugging Compile-Time Statements