http://www.perlmonks.org?node_id=252427

snafu has asked for the wisdom of the Perl Monks concerning the following question:

I am tailing a file with my program. Now, when I ''see'' a certain event I want to wait for $map_vTime seconds from the time that event was seen and then perform an action while all the while the loop continues to run.

Now, if the loop runs, great! My current way of doing this is for each iteration of the loop I update a hash %timer with the keys 'start', 'elapsed', and 'stop' where 'stop' is boolean, 'start' is when the event triggered, and 'elapsed' is (time() - 'start') (all done in seconds of course).

Here is my problem, since the loop is read only when something happens in the file (its a logfile for a game), theoretically, the timer could go on for n seconds (no players for example) before something gets read from the file again...way past a, lets say, 20 second timer which is the value I am using now.

So, this is not the behaviour I want. In fact, I tried using alarm() tied to signal handler. However, as in times past, I have encountered that unless the process is active time relative to alarm() doesn't actually remain constant or exact for that matter.

I considered using threads. However, giving the rough background and stern recommendations on the use of threads vs the current version of whatever Perl interpretter is installed on the box(es) I am not sure that using threads would be portable enough for me. In fact, two of the servers I am going to run this program on have 5.6.1 on them. I have direct root access control over one of these servers. When I attempt to install Thread.pm CPAN promptly states I need to upgrade to 5.8. Since I don't have the root access over one of the machines, it is not going to be an option for me to upgrade the interpretter.

So, to recap, Im trying to figure out the best way to perform an accurate timed event in a procedural manner that is portable to Perl 5.6.1 within a loop that is not constant in iteration.

Any thoughts? Time::HiRes? I have been looking into this module but I am not positive it has what I need.

TIA peeps.

_ _ _ _ _ _ _ _ _ _
- Jim
Insert clever comment here...