Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: missing second of time

by Anonymous Monk
on Feb 26, 2020 at 05:36 UTC ( [id://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; # 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; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-18 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found