in reply to Exiting from capturing output in a while?
Correct me if I'm wrong, but once Done returns (assuming you let it), the while() loop can't continue (since the INPUT file handle is closed), so program execution could proceed normally at that point. If that's the case, you might want to localize $SIG{ALRM}. You can also use a closure instead of a sub reference for the value of $SIG{ALRM}.$SIG{ALRM} = \&Done; alarm $timeout; # Set your timeout here, in secs while (<INPUT>) { print OUTPUT $_; # Do whatever } alarm 0; # So as not to trip ALRM after we're done +with INPUT close(OUTPUT); # Likewise, in case we got an EOF in INPUT + before $timeout close(INPUT); sub Done { close(OUTPUT); # Do your cleanup and optionally exit close(INPUT); exit 0; }
|
|---|