Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^3: missing second of time

by Anonymous Monk
on Feb 26, 2020 at 07:22 UTC ( #11113425=note: print w/replies, xml ) Need Help??

in reply to Re^2: missing second of time
in thread missing second of time

I tried the second solution with the fudge factor but it goes negative in less than an hour. I'll go back to the original suggestion and make sure the value is not negative before using it to sleep. Thanks again

Replies are listed 'Best First'.
Re^4: missing second of time
by tybalt89 (Parson) on Feb 26, 2020 at 15:51 UTC

    Try this one

    #!/usr/bin/perl use strict; # use warnings; use Time::HiRes qw( time sleep ); my $fudgefactor = 0.001; while(1) { my $time = time; my $nextsecond = int $time + 1; my $interval = $nextsecond - $time - $fudgefactor; $interval > 0 and sleep $interval; 1 while time < $nextsecond; printf "%.6f\n", time; }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2020-04-01 08:28 GMT
Find Nodes?
    Voting Booth?
    To "Disagree to disagree" means to:

    Results (186 votes). Check out past polls.