Search code examples
perldebuggingloopsskip

Perl Debugger - How to step out of a loop


While using perl debugger, is there any way to step out of the current loop?

For example:

line 1
for($i=1;$i<100000:$i++)
{
    line2
}
line3

I want the debugger to step out of this for loop and stop at line3


Solution

  • c 5
    

    Demonstration:

    >perl -d
    
    Loading DB routines from perl5db.pl version 1.33
    Editor support available.
    
    Enter h or `h h' for help, or `perldoc perldebug' for more help.
    
    print "line1\n";
    for (1..100000) {
       print "line2\n";
    }
    print "line3\n";
    ^Z
    main::(-:1):    print "line1\n";
    
      DB<1> s
    line1
    main::(-:2):    for (1..100000) {
    
      DB<1> s
    main::(-:3):       print "line2\n";
    
      DB<1> s
    line2
    main::(-:3):       print "line2\n";
    
      DB<1> c 5
    line2
    line2
    line2
    ...
    line2
    line2
    line2
    main::(-:5):    print "line3\n";
    
      DB<2> s
    line3
    Debugged program terminated.  Use q to quit or R to restart,