Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: 'better mousetrap': how to perform timed event

by Necos (Friar)
on Apr 24, 2003 at 17:04 UTC ( #252955=note: print w/replies, xml ) Need Help??

in reply to 'better mousetrap': how to perform timed event

Going on tachyon's idea, would it be possible to do something like this?
while (1) { $new_size = -s $file; if ($new_size > $old_size) { # $old_size is defined before this lo +op if ( event_occured() ) { sleep($map_vTime); do_your_thing(); $old_size = $new_size; } $old_size = $new_size; } sleep($normal_sleep_interval); }
I would figure, if the size of your log file changes, then you can easily seek to the point in your file that has changed (you do have the old file size), read the data from it (which should be fast if the new data is small), and decide if your event has indeed occured. If it's not your event, just fall out and go back to your polling. If it is, do your magic.

Hope that helps some.

Update: Not too long after my initial reply, I noticed that BrowserUK posted a much more elegant solution (maybe just a bit overkill?). The general idea still remains the same: check the filesize of your log. YMMV. Good luck.

Theodore Charles III
Network Administrator
Los Angeles Senior High
perl -e "map{print++$_}split//,Mdbnr;"

Replies are listed 'Best First'.
Re: Re: 'better mousetrap': how to perform timed event
by snafu (Chaplain) on Apr 25, 2003 at 23:44 UTC
    While your thoughts are decent a problem still persists. I probably haven't made this too clear, however. I cannot block during the read of the logfile. To do so would delay actions requested outside of the vote session by $map_vTimelimit seconds which would just be poor service to everybody trying to do things on the server during that vote session.

    Im thinking that the POE idea is going to be my best bet. The sample code Eduardo posted looks quite promising. Because what I am looking for is a ''backgrounded timer'' which doesn't block that I can monitor for completion so when it is done counting I can proceed to call a sub-routine.

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://252955]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-06-13 14:11 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (55 votes). Check out past polls.