A similar problem was discussed in The most precise second (timer).

If you don't need to be almost precise, something like this might be good enough:

#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; use Time::HiRes qw{ time sleep }; sub func { sleep rand 0.05 } my $t0 = 0; while (1) { if (time - $t0 >= 0.1) { say $t0 = time; func(); } }
On my machine, it shows:
1597188470.0211 1597188470.1211 1597188470.2211 1597188470.3211 1597188470.4211 1597188470.52111 1597188470.62111 1597188470.72111 1597188470.82111 1597188470.92111 1597188471.02111 1597188471.12111 1597188471.22112 1597188471.32112 1597188471.42112 1597188471.52112 1597188471.62112 1597188471.72112 1597188471.82113

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

In reply to Re: Call function no more than every 0.1 seconds by choroba
in thread Call function no more than every 0.1 seconds by zapoi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.