in reply to on event but after an interval?
One technique you could use is to set an alarm. Consider:
use strict; use warnings; waitForSomeTime (); sub waitForSomeTime { my $bail; local $SIG{ALRM} = sub {$bail = 1}; alarm 5; # Bail in 5 seconds if we don't stop beforehand while (! $bail) { # Do stuff in here that might terminate the loop # but don't use sleep() because alarm may get grumpy } if ($bail) { print "Must have bailed\n"; } else { alarm 0; # Reset the alarm print "Loop terminated some other how\n"; } }
|
|---|