Have you considered using POE ?
If you have Time::HiRes installed, POE::Kernel will use it for timed events.
And your code will be much shorter, with more elegant structure, and thus
easier to maintain.
Here is a simple scheduler example:
use POE;
$DELAY = 0.5; # every half a second
sub do_something {
my $kernel = $_[KERNEL];
print "Hello boy..\n";
$kernel->delay('wake_up!', $DELAY);
}
POE::Session->new(
_start => sub {
my $kernel = $_[KERNEL];
$kernel->delay('wake_up!', $DELAY);
print "Session is started..\n";
},
_stop => sub {
print "Session is stopped.\n";
},
'wake_up!' => \&do_something,
);
$poe_kernel->run;
I have not yet come across POE. Will do some reading. I'm never sure what happens after/inside run (where do I run my normal code that is not related to the POE code ... newbie warning!) Will do some reading...<sigh>