in reply to Timers/running (something) after (sometime)

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.