On 2011-06-15 14:18, C.DeRykus wrote:
[...] mixing
alarm/sleep is a bad idea. See: perldoc -f alarm.
Another solution, not necessarily more elegant, but
more familiar to most is an eval {} and alarm pair:
EVAL: {
eval {
local $SIG{ ALRM } = sub { die "alarm"; };
local $SIG{ USR1 } = sub { die "usr1" };
alarm $sleeptime;
... some long running operation here ....
alarm 0;
1;
} or do {
Insert:
my $eval_error = $@ || "Zombie error!";
and use $eval_error in the code below.
alarm 0;
if ( $@ =~ /alarm/) { warn "expired..." }
} elsif ( $@ =~ /usr1/) { redo EVAL; }
} elsif ($@) { die "unexpected error: $@"; }
}
}
Realize that $@ is a global variable, so can get changed at a distance.
The last 'elsif' was particularly wrong: it would not die if $@ is
false. Just make it an 'else'.
--
Ruud
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/