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

I am trying to poll for asynchronous input. Given this code snippet
for (;;){ #something pause for 10ms }
what's the best way to actually pause the loop and give the processor to other processes? It seems like Sleep() only handles seconds.

Replies are listed 'Best First'.
Re: Millisecond Pause
by Juerd (Abbot) on Jan 04, 2002 at 01:05 UTC
    If you wait for input, you should probably use the four argument select. Or better: IO::Select.

    If you really just want to wait for less than a second, well, use the four argument select anyway ;) select(undef, undef, undef, 0.1) will wait for 1/10 of a second.
    Another solution is to use Time::HiRes for that: use Time::Hires qw(sleep); sleep 0.1;

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

Re: Millisecond Pause
by slloyd (Hermit) on Jul 23, 2005 at 14:13 UTC