Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Is it possible to issue a perl command to sleep for less than 1 second?

by zentara (Archbishop)
on Aug 24, 2007 at 14:49 UTC ( [id://634885]=note: print w/replies, xml ) Need Help??


in reply to Is it possible to issue a perl command to sleep for less than 1 second?

select(undef,undef,undef, .1); #100 millisecond delay

I'm not really a human, but I play one on earth. Cogito ergo sum a bum
  • Comment on Re: Is it possible to issue a perl command to sleep for less than 1 second?

Replies are listed 'Best First'.
Re^2: Is it possible to issue a perl command to sleep for less than 1 second?
by davido (Cardinal) on Aug 24, 2007 at 15:29 UTC

    Yes, that is a simple method. See select, where it states:

    You can effect a sleep of 250 milliseconds this way:

    select(undef, undef, undef, 0.25);

    Dave

Re^2: Is it possible to issue a perl command to sleep for less than 1 second?
by amarquis (Curate) on Aug 24, 2007 at 17:33 UTC

    I'd have never thought up this usage of select. Is it a trick used for fractional second sleeps from before Time:HiRes existed?

      It's been around forever(since C was created). Most people discover it when first doing a "perldoc -q sleep" and are referred to "perldoc -f select". Ultimately it is based on the c code, where select can be used as a delay if the file descriptors are left undefined. Read "man select" if you want to know how it's magic works.

      Now that you know, you will probably recognize it in alot of code. I usually put an inline comment when I use it, signifying it is used for a delay, so the uninitiated will get it.


      I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://634885]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-19 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found