Perhaps rather than reinventing wheels use AnyEvent and EV to setup a timer event to be posted every second.
$ perl -MTime::HiRes=time -MAnyEvent -E '$quit = AnyEvent->condvar;$w
+= AnyEvent->timer( after => 1, interval => 1, cb => sub { state $ctr
+= 1; say "@{[Time::HiRes::time()]}: FOOP! $ctr"; $quit->send if 10 ==
+ $ctr++; } );say qq{Starting loop};$quit->recv;'
Starting loop
1574791289.26471: FOOP! 1
1574791290.26702: FOOP! 2
1574791291.26394: FOOP! 3
1574791292.26511: FOOP! 4
1574791293.26735: FOOP! 5
1574791294.26826: FOOP! 6
1574791295.26665: FOOP! 7
1574791296.265: FOOP! 8
1574791297.26659: FOOP! 9
1574791298.26699: FOOP! 10
$
The cake is a lie.
The cake is a lie.
The cake is a lie.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|