in reply to Re: sleep in while loop
in thread sleep in while loop

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 ?

Replies are listed 'Best First'.
Re: Re: Re: sleep in while loop
by Shendal (Hermit) on Aug 05, 2002 at 16:06 UTC
    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.