in reply to Stopping code in eval

At Perl docs on using ALRM for a timeout you will find exactly your problem addressed. If you prefer paper, a slightly longer discussion is in the camel book, Programming Perl, 3rd Ed., Ch. 16 starting in the secon section, "Signals", and continuing through "Timing out Slow Operations" both discussions are quite good.

The link includes the following code (to wet your appetite), but don't just read it and mis out on the discussion. Follow the link, where the code is even chromacoded.

eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required alarm $timeout; $nread = sysread SOCKET, $buffer, $size; alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; # propagate unexpected errors # timed out } else { # didn't }
Update: Added ", 3rd Ed."