good chemistry is complicated,
and a little bit messy -LW
Time::HiRes strange behaviorby golden.radish (Initiate)
|on Feb 05, 2010 at 22:21 UTC||Need Help??|
golden.radish has asked for the wisdom of the Perl Monks concerning the following question:
I'm having a problem with Time::HiRes, specifically the gettimeofday function. Below I've given a code sample and instruction on how to duplicate the problem. It will only take a few seconds to confirm/refute the problem, if you have the time. Please and thank you in advance.
Context: The purpose of this code is simply to prepend a timestamp (with ~microsecond accuracy) to any lines, entries, stdout, whatever you'd care to feed the script.
Observe the microsecond value on the output (it will be something like this, not exactly):
The microsecond value from 'gettimeofday()' increments by a small amount each time a new line is added, and entirely inaccurately. As you add more output to the file, you'll see that the microsecond value increments for every entry, but entirely not what it should be.
Now contrast this output with the behavior when you simply press enter a few times if you run the script by itself:
Which is working as expected. The values increment, but not predictably, and certainly not by very small values as observed above.
Tested & verified this behavior on:
perl, v5.10.0 built for i486-linux-gnu-thread-multi
perl, v5.8.8 built for i486-linux-gnu-thread-multi
perl, v5.8.4 built for sun4-solaris-64int
Any thoughts would be greatly appreciated. What is causing this strange behavior when piping the output from a tail -f into the script?