perl5ever has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to programmatically break into the debugger, e.g. something like:
sub foo { ... DB::break(); # force a call to the debugger here ... }

Replies are listed 'Best First'.
Re: programming a break point
by Eliya (Vicar) on Feb 24, 2011 at 17:27 UTC

    You could do something like this:

    #!/usr/bin/perl -d BEGIN { DB::parse_options("NonStop=1") } # non-stop mode sub foo { $DB::single = 1; # break (at next line) my $foo = "foo"; my $bar = "bar"; } foo();
Re: programming a break point
by vkon (Curate) on Feb 24, 2011 at 17:50 UTC
    yes, it is.

    Place following line into your program:

    $DB::single=1;
    and then run with debugger available
    perl -d foo.pl
    or even better
    perl -d:ptkdb foo.pl
    or even better more
    perl -d:tkdb foo.pl
    last mentioned one does not offer same feature set as ptkdb, but very soon will do even much better, as it has large amount of optimizations.

    in case of perl -d foo.pl you will need to type 'r' once your program starts to make it run.

    update: removed DB::DB(); as it is actually not needed, thanks to wisdom from Eliya