File Input/Output :: Error Handling
What if we can get a filehandle? We should handle this case graciously by using die. For example:
open (inf, "/some/directory/file.in") || die "cannot open: $!";
So what does this do? Perl tries to open file.in OR it calls die with the string. The $! contains the most recent system error, so it will append a useful tag to the output of die. You could even make a dienice subroutine that could be more helpful. You can exit a Perl program immediately by calling exit;.
No comments:
Post a Comment