Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^2: missing second of time

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

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

Greeting monks, OP here. Thanks for all the input. I implemented tybalt89's solution (int time + 1) - time and the program ran for about a month until it crashed with this cool error:
Time::HiRes::sleep(-0.202505): negative time not invented yet
I don't know why that happened but I'm going to try tybalt's other solution at Re: missing second of time and see what happens... Peace, Love and Perl

Replies are listed 'Best First'.
Re^3: missing second of time
by Anonymous Monk on Feb 26, 2020 at 07:22 UTC
    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

      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://11113423]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2020-04-10 06:53 GMT
Find Nodes?
    Voting Booth?
    The most amusing oxymoron is:

    Results (49 votes). Check out past polls.