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 (Monsignor) on Feb 26, 2020 at 15:51 UTC

    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; }