in reply to Avoiding INIT

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

Replies are listed 'Best First'.
Re^2: Avoiding INIT
by geoffleach (Scribe) on Feb 09, 2010 at 16:23 UTC
    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?

        The idea it to postpone processing the command line until the last moment. The INIT block is just one sub call, prefixed, of course with an underscore to suggest that you (the user) really does not want to go there.

        The idea is to eliminate a potential source of confusion. I know that when I was developing tests I was constantly asking myself, "WTF is this?" before remembering that I was looking at the INIT block -- which I had written of course :-(.

      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.

        Well, fair enough. But that's only because you didn't RTFM :-)