http://www.perlmonks.org?node_id=11113423


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; # https://perlmonks.org/?node_id=11111868 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; }