in reply to using "alarm" with SIGALRM

adopted from perldoc -f alarm
#!/usr/bin/perl use strict; use warnings; my @time=(4,12,16,8); LABELME: foreach my $t (@time) { eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required print "Start $t\n"; alarm(10); sleep($t); alarm(0); print "done with $t\n"; }; if ($@) { die unless $@ eq "alarm\n"; # propagate unexpected errors print "timeout\n"; next LABELME; } else { # didn't } } print "All Done!\n";

Replies are listed 'Best First'.
Re^2: using "alarm" with SIGALRM
by jb_using_perl (Initiate) on Jul 27, 2009 at 18:39 UTC
    Thank you! That worked perfectly.
    -jb_using_perl