Yes, yes, I know there are modules ;) but at this point, it'd be a major pain to rewrite it, and I don't like most of the modules.

I'm using a while in my main code (on an IO::Select) to get the input.

I've got some code which works GREAT by itself... but with small adaptations to make it fit in my bot code it just plain doesn't work; it quits when it gets out of the SIGALRM handler.

#!/usr/bin/perl use warnings; sub after { my ($time, $anonsub) = @_; do { $id = int(rand(10000)); } while (defined($times{$id})); $times{$id} = $time; $subs{$id} = $anonsub; } sub Alrm { for (keys(%times)) { if (time() >= $times{$_}) { ${subs{$_}}(); delete $times{$_}; } elsif (time() < $times{$_}) { next; } } alarm 1; } $SIG{ALRM} = \&Alrm; alarm 1; print gmtime(time()).chr(10); sub DoStuff { print gmtime(time()).chr(10); after(time+1, \&DoStuff); } after(time+1, \&DoStuff); 1 while 1;

So, I don't know. I may just trash this. And when I do my major rewrite I've already got planned I may switch to a module. But... not yet.


In reply to Re: Timers/running (something) after (sometime) by dimecadmium
in thread Timers/running (something) after (sometime) by dimecadmium

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.