http://www.perlmonks.org?node_id=274965

mgibian has asked for the wisdom of the Perl Monks concerning the following question:

This seems like such a fundamental question, but even though I've written thousands of lines of working Perl, I am quite puzzled by this issue.

I am writting a comprehensive set of scripts for building some software. Two features are that it must log comprehensively to a file anything of use in addition to providing some informative and progress messages to stdout; and, it must be very comprehensive in its error handling.

What has me puzzled is how one captures error information for many of the basic functions within Perl, and more specifically file related functions such as open, close, copy, unlink as a few examples. The common practice for these is to code up:

open(...) or die ".... $!"
My script needs to be more sophisticated in what it does in the error case than doing a simple die. I am guessing that I can put any code I need in the or case, but I have not seen any examples. Also, is the $! just a textual error message? I am thinking something like:
open (...) or { $errormsg = $!; $status = -1 }
or something similar would do the trick?

Anyone out there have any experience in doing more complete and rigorous error handling in Perl?