When the reading end of a pipe is closed, and the writing process tries to write something to a pipe, then the writing process receives a SIGPIPE
. The pipe is called broken.
We can capture this event like
local $SIG{PIPE} = sub {
# This is our event handler.
warn "Broken pipe, will exit\n";
exit 1;
};
This would gracefully exit your program. Instead of installing a sub as event handler, you could give the string IGNORE
. This would let your script carry on as if nothing happened.
# print will now return false with $!{EPIPE} true instead of dying
local $SIG{PIPE} = 'IGNORE';