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

I'm curious if there's an advantage to using the Win32::Sleep() function over Perl's own sleep() routine. The only obvious one I see is that the Win32 version is in milliseconds, giving it greater granularity. But there are ways to do that with select() without introducing portability problems. Is there any other reason I should use Win32::Sleep when writing programs for the Win32 platform, instead of sleep() or select()?

Replies are listed 'Best First'.
RE: Sleeping with the Enemy
by Carl-Joseph (Scribe) on Aug 26, 2000 at 00:29 UTC
    Keep in mind that the Win32 Sleep API behaves differently from Perl when the argument passed is zero. Presumably, when the Perl sleep() function is passed zero, your script sleeps for zero seconds, i.e. returns immediately. (I say "presumably" because I haven't actually tested this.) However, an argument of zero causes the Win32 Sleep API to give up the rest of its time slice. Depending on what other threads are running, it could be more than zero milliseconds before your script is running again.
Re: Sleeping with the Enemy
by Adam (Vicar) on Aug 26, 2000 at 00:12 UTC
    I'm curious. How do you use select to cause the script to sleep for a time with a greater granularity then seconds?

    Thanks!

      The fourth argument to select specifies a timeout. If you call it with blanks for the first three arguments and a value for the fourth it will timeout for that long. For example, you can effect a sleep of 250 milliseconds this way:
      select(undef, undef, undef, 0.25);
      See the perlfunc bit on select...
      From perldoc -f select:
      You can effect a sleep of 250 milliseconds this way: select(undef, undef, undef, 0.25);
      While sleep() is usually good enough, select() comes in handy sometimes.
A reply falls below the community's threshold of quality. You may see it by logging in.