Alex Rivera | Logout

How do I sleep for a millisecond in Perl?

Asked 2009-05-22T08:38:21.957
89

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

Edit
Report

2 Answers

40

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

answered 2009-05-22T08:43:28.577
15

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).

answered 2009-05-22T11:21:45.620

Your Answer