in reply to sleep in while loop

What do you mean by "it just hangs"?
while (1) { ... do something ...; sleep 10 }
isn't going to terminate, unless you exit the loop from the do something part.

Abigail

Replies are listed 'Best First'.
Re: Re: sleep in while loop
by Anonymous Monk on Aug 05, 2002 at 16:00 UTC
    I don't want it to exit from the loop, when I say it just hangs I mean it doesn't execute any other code, it just seems to go straight to the sleep function and stay there. I want the prog to loop indefinitely until it is killed by the user. i.e: while (1) { if($cond = 1){ print "1"; } else{ print "2"; } sleep 10 } it doesn't do the conditional statements (just eg's) or any other statements in the prog, it just hangs on the cmd line: ./prog.pl Huh ?
      You may be getting bitten by buffering. Try this:
      $|++; # force auto-flush (see perldoc perlvar) while (1) { if ($cond == 1) { print "1\n"; } else { print "2\n"; } sleep 10; }

      Cheers,
      Shendal
        Thanks - buffering was biting my proverbial ***- by the way the code in the loop was not the actual code - sorry to confuse the issue.