#!/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";
In reply to Re: using "alarm" with SIGALRM
by Anonymous Monk
in thread using "alarm" with SIGALRM
by jb_using_perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |