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

This code,

#!/usr/bin/perl
INIT {
print "here INIT\n";
}
print "here main\n";

prints

here INIT
here main

as expected. Also (as expected, I assume) when its run with perl -d, the debugger starts at print "here INIT\n";

My question: is there any way to tell Perl NOT to do that, and to stop at the first (next) statement in the body of the code?

Replies are listed 'Best First'.
Re: Avoiding INIT
by ikegami (Patriarch) on Feb 09, 2010 at 02:20 UTC

    My question: is there any way to tell Perl NOT to do that, and to stop at the first (next) statement in the body of the code?

    So you're asking for a means to have the debugger skip over some of the program? It doesn't make much sense to have a debugger that skips over pieces of code. You'll have to add a condition to the code.

    #!/usr/bin/perl INIT { return if $ENV{DEBUG_SKIP_INIT}; print "here INIT\n"; } print "here main\n";

    Then launch the debugger using

    DEBUG_SKIP_INIT=1 perl -d
      Thanks for the replies. Here's the context.

      The module Getopt::Auto provides "magic" processing of command-line options. It uses processing in the INIT block to look at the command line before the body of the user's script is executed.

      Thus, the INIT block is part of the user's code for execution purposes, but from the user's point of view, it isn't.

      I'm just looking for a way of having the user not see the code. Sort of the opposite of $DB::single = 2.

        Ah, you don't want to skip it's execution, you want to have the debugger not step through it. I'm rather surprised BEGIN blocks are simply executed rather than stepped through.

        Any reason you don't move the contents of your INIT block into your CHECK block?

        Actually, if I had to go into the debugger to find out what/who is messing with @ARGV, and your code didn't show up in the debugger, I would be very unhappy.

Re: Avoiding INIT
by planetscape (Chancellor) on Feb 09, 2010 at 00:43 UTC

    Or comment out what you don't want to run, as per Re: Using the perl debugger?

    I do not believe you are providing sufficient information re: what you really want to accomplish.

    HTH,

    planetscape
Re: Avoiding INIT
by SuicideJunkie (Vicar) on Feb 08, 2010 at 22:33 UTC
    Why not simply set a breakpoint at the line you want to stop at, and then let it run until it gets there?
    Did you need this to be automatically done each time you start the debugger with that specific program?