Using only CORE functionality:

use 5.14.0; use warnings; use Time::HiRes qw( ualarm gettimeofday usleep ); my $delay = 100_000; # us my $x = 0; sub foo { my $duration = rand 1200; # Some will be longer than the max durat +ion my ($sec, $msec) = gettimeofday; printf "%4d %12d.%03d %6d\n", $x++, $sec, int ($msec / 1000), $dur +ation; vec (my $v, 13, 1) = 0; select ($v, $v, $v, $duration / 10000.); } # foo my $running = 0; $SIG{ALRM} = sub { ualarm ($delay); unless ($running) { $running = 1; foo (); $running = 0; } }; ualarm (10); usleep (10) while 1;

-->

$ perl test.pl 0 1597222014.930 430 1 1597222015.030 543 2 1597222015.131 362 3 1597222015.231 1059 4 1597222015.337 929 5 1597222015.437 611 6 1597222015.537 1027 7 1597222015.640 396 8 1597222015.740 243 9 1597222015.840 1095 10 1597222015.950 710 11 1597222016.050 674 12 1597222016.150 695 13 1597222016.250 842 14 1597222016.350 901 15 1597222016.450 468 16 1597222016.550 568 17 1597222016.650 322 18 1597222016.750 633 19 1597222016.850 194 20 1597222016.950 1141 21 1597222017.064 365 22 1597222017.165 226 23 1597222017.265 1162 24 1597222017.381 998 25 1597222017.481 543 26 1597222017.581 184 27 1597222017.681 197 28 1597222017.781 431 29 1597222017.881 1081 30 1597222017.990 644 31 1597222018.090 49 32 1597222018.190 500 33 1597222018.290 1137 34 1597222018.404 171 35 1597222018.504 995 36 1597222018.604 847 37 1597222018.704 998 38 1597222018.804 262 39 1597222018.904 1043 40 1597222019.009 292 41 1597222019.109 668 42 1597222019.209 805 43 1597222019.309 886 44 1597222019.409 361 45 1597222019.509 676 ^C

Enjoy, Have FUN! H.Merijn

In reply to Re: Call function no more than every 0.1 seconds by Tux
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.