On Wed, 08 Feb 2006, Todd Morrison wrote:
> I was wondering if anyone knows/has had experience with using sleep() in a
> conditional context. For example...
> 
> for ($x=0; $x<= 10; $x++) {
>          print "$x\n";
>          # if x is equal to 5, sleep for 5 seconds
>          if ($x == 5) { sleep(5); }
> }
> 
> What I wanted to accomplish with this loop was to have the iteration run
> until the condition was met, at which point the loop would sleep for 5
> seconds. Is there a way I can accomplish this? When I run the code, above,
> what actually happens is the entire script/code waits for 5 seconds and
> *then* launches the loop.
> 
> Any advice or direction would be super.

It is actually working as you want it to.  You just don't see the output
earlier because you didn't turn on autoflush for the STDOUT filehandle.
Just add

    $| = 1;

to the top of your script.

Cheers,
-Jan


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to