$DB::single = 1 : Make that debugger stop where you want it

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.

 

 

 

Post to Twitter Post to Digg Post to Facebook Send Gmail Post to LinkedIn Post to Reddit Post to StumbleUpon

About Tom
I work in a healthcare technology startup. These days, I attempt to code in Perl, and this blog is about the Wild Perl we write, startup life, and many other things.

One Response to $DB::single = 1 : Make that debugger stop where you want it

  1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>