Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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 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...

In reply to 'better mousetrap': how to perform timed event by snafu

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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 or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2021-05-18 16:12 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (181 votes). Check out past polls.