But I need better resolution than one second.
Oh, sorry, didn't listen carefully. Then use Time::HiRes, which is a core module on newer perls:
perl -we 'use Time::HiRes "time"; print time, "\n";'
or the gettimeoftheday function from the same module, or (on linux)
perl -we 'defined(syscall 78, ($d = pack "x100"), 0) or die "panic: ge
+ttimeofday failed $!"; ($s, $u) = unpack "l!l!", $d; printf "%d.%06d\
+n", $s, $u;'
but 156 instead of 78 on solaris, and 116 (untested) instead of 78 on freebsd, (Update:) 96 instead of 78 on linux-x86_64.
Update:
Before every tick, get the current time, and wait whatever time is left till the next tick.
That's essentially what I'm already doing.
My point is that you have to ask for the time before every sleep. I don't see your code, so you might already be doing that. Of course, if you spawn an external process for querying the time, then that's slow, so don't do that.
-
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.