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

I am exploring the capabilities of perldebug. Is there a way to "skip" a step?

Definition of "skip" : What would otherwise be executed when 's' or 'n' is entered, is not executed.

Does this involve messing with perldebguts by modifying DB::sub()?

Out of curiosity, would it be possible to dynamically modify a line statement via the interactive debugger?

Replies are listed 'Best First'.
Re: How to skip a step in perldebug?
by casiano (Pilgrim) on Aug 07, 2008 at 08:37 UTC
    You can skip some code if you label the target statement as illustrated in the following example:

    pp2@nereida:~/Ltesting$ perl -wd skipdeb.pl Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(skipdeb.pl:2): my $a = 4; DB<1> l 2==> my $a = 4; 3: my $b = 4; 4: my $c = 4; 5 6: $a = 5; 7: $a += 1; 8: L:$a = $c*$a; 9: $a = $c*$b; 10: print "$a\n"; DB<1> c 6 main::(skipdeb.pl:6): $a = 5; DB<2> b 9 DB<3> goto L main::(skipdeb.pl:9): $a = $c*$b; DB<4> p $a 16
    The value of $a is 16. We have skipped statements 6 and 7.

    Hope it helps

    Casiano

      Casiano, thanks for replying.

      I'm afraid that this approach is slightly lacking: If I knew enough to place a label where I would like to skip, I might as well have commented the skipped line(s) out.

      It would be nice to dynamically decide which code executions to skip, after running perl -d only once.

      What would work is a goto [line_number].
Re: How to skip a step in perldebug?
by casiano (Pilgrim) on Aug 07, 2008 at 09:04 UTC
    Regarding your second question
    would it be possible to dynamically modify a line statement via the interactive debugger?
    I also don't know.
    What I do is the same trick that in the previous solution but before the goto L I do the "substituting" statement like in:
    pp2@nereida:~/Ltesting$ perl -wd skipdeb.pl Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(skipdeb.pl:2): my $a = 4; DB<1> l 2==> my $a = 4; 3: my $b = 4; 4: my $c = 4; 5 6: $a = 5; 7: $a += 1; 8: L:$a = $c*$a; 9: $a = $c*$b; 10: print "$a\n"; DB<1> c 6 main::(skipdeb.pl:6): $a = 5; DB<2> b 9 DB<3> $a = 8 # This statement substitutes the skipped ones DB<4> goto L main::(skipdeb.pl:9): $a = $c*$b; DB<5> p $a 32
      Yes, skipping & entering your own code expression instead is akin to modifying the line statement.

      I was also wondering about issues like breaking scope, etc. Here's a made-up example:
      1: while (<STDIN>) { 2: push(@F, $_); 3==> shift(@F) if $. > 10; 4 }
      I wish to replace line 3 with
      shift(@F) if $. > 10; }{ print @F;
      instead. This modification still results in valid code.

      How far can we push this?