Hi,
I'm writing a script and am looking for the best way to proceed. I have an interface that allows you to request a some data. The following works fine for single event...
->log abc
I want to make it so that I setup timed events i.e.
-> log abc ontime 1
so that the info would come out periodically and multiple logs could setup etc.
To process my command line input I'm just using the
readline module...i.e.
while(defined($_ = $term->readline($prompt))) {
[case statement to parse command]
}
this works fine for single entries, but readline is blocking so that I can't put any other code in the while loop that will trigger until another command is issued.
So what I'd like is either a good way to piggy back onto what I have with something that can be added periodically or rewrite it a better way...
i.e.
while (not time to quit) {
[see if there is keyboard stuff to process]
[process any timer based stuff]
[go back to sleep]
}
I tried using signals to keep the other code the same, but because you run into problems with reentrancy of code the signal stops after a few operations.
I expect there is a very clean way of doing this in perl as the problem is pretty straight forwards. The periodicity is only going down to a 1second level so I don't need any complex sub-second routines.
I have setup the backend for the timing ready for the triggers from whatever source. I'm basically using a hash with the key being the update rate and the value being a reference to an array of logs that are requested at that rate. So the event timer just will just look at the key to work out which groups to process when and takes it from there.
If anyone can point me in the right direction, offer a code snippet, an example of someone else that does this or a module for this type of thing it would be much appreciated..
Regards Paul.