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

just a little question, will this command - "sleep(2.5);" - sleep for two and a half seconds ?

Replies are listed 'Best First'.
Re: sleep(2.5)
by davido (Cardinal) on May 10, 2004 at 03:52 UTC
    No, sleep won't work with FP precision. Try this instead:

    select undef, undef, undef, 2.5;

    ...That'll do it. See the POD for select for a full explanation.


    Dave

Re: sleep(2.5)
by saskaqueer (Friar) on May 10, 2004 at 03:57 UTC

    sleep can only sleep for an integer amount of time. Essentially, anything you pass to sleep will seem as though you did sleep( int(###) );. So sleep( 2.5 ) will sleep for 2 seconds, not 2.5. There are two solutions: use select as davido says (select( undef, undef, undef, 2.5 )) or else pull in the Time::HiRes module to replace the sleep command with one that works with floating point sleep times:

    use Time::HiRes qw( sleep ); sleep( 2.5 );
Re: sleep(2.5)
by PodMaster (Abbot) on May 10, 2004 at 05:26 UTC
Re: sleep(2.5)
by greenFox (Vicar) on May 10, 2004 at 06:01 UTC
Re: sleep(2.5)
by samtregar (Abbot) on May 10, 2004 at 18:14 UTC