in reply to Why <c>eval {...};if ($@) { die $@ } else { ...</c> ???
{ local $SIG{__DIE__}; local $@ = ""; eval { local $SIG{ALRM} = sub { die("alarm\n") }; alarm(3); chomp($input = <STDIN>); # potentially long operation alarm(0); 1; } or do { die($@) unless $@ eq "alarm\n"; # timed out warn("No answer for three seconds.\n"); $input = ""; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why <c>eval {...};if ($@) { die $@ } else { ...</c> ???
by jplindstrom (Monsignor) on Apr 06, 2009 at 14:27 UTC |