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

Is there a way to re-execute lines for code other than just re-executing the file. Something like:
code code code code wait 20 go back and execute line 1 through 4

Replies are listed 'Best First'.
Re: Re Execute Lines of Code
by hipowls (Curate) on Jan 27, 2008 at 12:14 UTC

    Do you mean something like?

    for ( 1 .. 2 ) { #do stuff here sleep 20; }

    Which will run the code in the block twice with a 20 second pause between runs.

      I am currently trying this one now. Thanks for your help.
        Good that you're trying that one, because it's sleep, not wait ;-)
Re: Re Execute Lines of Code
by moritz (Cardinal) on Jan 27, 2008 at 12:09 UTC
Re: Re Execute Lines of Code (middle-tested)
by ikegami (Patriarch) on Jan 27, 2008 at 12:44 UTC

    If you only want to do the wait in between "codes" and not at the end,

    my $times = 2; for (;;) { code; last unless --$times; wait; }
      { wait == -1 and print "no child left behind!" or redo }

      I'd use sleep.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Re Execute Lines of Code (redo)
by ikegami (Patriarch) on Jan 27, 2008 at 12:57 UTC
    Depending on what you are doing, redo might be a better fit.,
    LOOP: { try something; if (!success) { wait; redo; } }
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Re Execute Lines of Code
by apl (Monsignor) on Jan 27, 2008 at 21:31 UTC
    Unlike my brethern, I'd code it as
    Routine(); sleep 20; Routine(); sub Routine { code; code; code; code; }
    If it was important enough to do twice, you might need to do it again, later on...