Some more cleanup you should consider to try and find your bug(Im not sure where the bug is, but my cleaned up version works!):
- Put use strict; use warnings; at the start!!!
- Put the init of the timer in a separate sub. You do exactly the same thing in 3 different places(twice in add_schedule, once in set_next_alarm)
- Try do decide if you want to use %schedule as a global variable or as an argument to the functions. You use it both ways in several places, which is quite confusing.
- Whats with all the extra blocks and the eval where you initilize all the events? Try cleaning that section up, and you might notice a few useless statements that can be removed.
- Try marking out all the debugging code a bit clearer. Its kind of hard to see what is debugging statements and what is actually code.
- Oh, and since you allready have accessor functions for %schedule, try using them whenver you manipulate the hash. Makes it a lot easier if you want to try and make it more efficient later on.
- Perhaps the checking for the alarm and executing the event should be a separate sub? What about just setting
$alarm_triggered to one when you you decide that the next event should be executed imediately, and bypassing the alarm?
Btw, what version of perl are you using, and on what platform. I seem to remember that there was some problem with signal handling some versions ago.
Good luck,
Goldclaw