[perl] How do I sleep for a millisecond in Perl?

How do I sleep for shorter than a second in Perl?

This question is related to perl sleep

The answer is



From perlfaq8:


How can I sleep() or alarm() for under a second?

If you want finer granularity than the 1 second that the sleep() function provides, the easiest way is to use the select() function as documented in select in perlfunc. Try the Time::HiRes and the BSD::Itimer modules (available from CPAN, and starting from Perl 5.8 Time::HiRes is part of the standard distribution).


A quick googling on "perl high resolution timers" gave a reference to Time::HiRes. Maybe that it what you want.


Time::HiRes:

  use Time::HiRes;
  Time::HiRes::sleep(0.1); #.1 seconds
  Time::HiRes::usleep(1); # 1 microsecond.

http://perldoc.perl.org/Time/HiRes.html


system "sleep 0.1";

does the trick.