http://www.perlmonks.org?node_id=418297

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

Hi,
Anyone knows how to use "exit" in the code and than restart again after few seconds, like:

perl code here...
#stop for 3 seconds using exit;
exit;
#now, restart the rest of the code
rest of the perl code here...

Any one? Thank you!

Replies are listed 'Best First'.
Re: Using exit
by dragonchild (Archbishop) on Dec 30, 2004 at 16:32 UTC
    You probably want to look at sleep, not exit.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re: Using exit
by steves (Curate) on Dec 30, 2004 at 16:34 UTC

    exit will cause the process to stop running. To restart it and pick up at another location, you'd have to save some sort of data before exiting that would tell you where to pick up, then load and use that data to conditionally execute code on restart. This doesn't sound like a good design to me. Are you sure you don't want to just sleep for 3 seconds, then continue on?

      Tried but it doesn't work the way I want cause when I use sleep(3); it doesn't display what I already have processed on the browser it just seats there and of course "sleep" for 3 seconds. and using exit displays everything at that point to the browser, I just need some similar trick to display whatever at some point in my program and than move on.
        if you're trying to get things to display to the browser, there are other things to do:
        $|++;
        to force writes to be "immediate". (i'm forgetting the proper term .. not enough coffee yet this morning ... )

        the reason  exit is sending the output to the browser is because the write buffer is closed, like a  close on a filehandle.

        It sounds like you are developing a CGI application. If this is the case, turning off output buffering may ensure that the output from the script is displayed in the browser:
        $|++;
Re: Using exit
by The Mad Hatter (Priest) on Dec 30, 2004 at 16:32 UTC
    I think your best bet is to sleep the process rather than terminating it.