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.

In reply to Event timing and input processing by thekestrel

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.