in reply to perl -d at runtime?

You can definitely do this in your script:

#!/usr/bin/perl -d

... loads up the debugger correctly.

So what if you had two versions of your script ... one with -d in the shebang line, and one without? Call the -d version when your condition requires it. Sloppy but it works.

Replies are listed 'Best First'.
Re: Re: perl -d at runtime?
by QM (Parson) on Dec 20, 2003 at 01:15 UTC
    Reworking davido's idea above:
    if ( ( do_I_want_debug ) and ( not defined( $DB::VERSION ) ) # already in debug? { exec('perl -d $0 @ARGV') or die $!; }
    I can't remember the variable to check if the debugger is running. $DEBUGGING used to work, but not here on ActiveState 5.8.0.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      I ended up stripping the -d arg and using exec.
      #!/usr/bin/perl -w BEGIN { # handle -d by itself to start the debugger @ARGV = grep { $_ eq '-d' ? !($opt_d=1) : 1 } @ARGV; exec('/usr/bin/perl','-dS',$0,@ARGV) if $opt_d; } ...
      Note that this doesn't do clustering like smarter switch process.

      Also, I don't know if I need that -S but it's not hurting yet.