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


in reply to Re: Sending filehandles?
in thread Sending filehandles?

I've ... included $! in die.

You've only done half the job there :-). If you don't put both the filename and the OS error in the error message, the user can't diagnose the actual problem. OP's (unhelpful) error message:

Could not open file
Your (fractionally more helpful) error message:
Could not open file: Permission denied
This:
open(my $FILEHANDLE, ">", $filename) or die "Cannot open $filename: $!";
yields a helpful error message:
Cannot open /dev/secret: Permission denied
To be super-picky, it's "Cannot open", not "Can't open", or "Could not open", or any other variation. In English, at least.

Replies are listed 'Best First'.
Re^3: Sending filehandles?
by DrHyde (Prior) on Feb 12, 2008 at 11:07 UTC

    Ahhh, a useless spelling and/or grammar criticism. Which is, of course, wrong, as such things always are. "Can't open" is just fine. "Can not" needs a space in the middle.

    But a good point about spitting out the filename in the error message.

      Well it wasn't intended to be a 'spelling or grammar' criticism, is was meant to be a 'standard error message' criticism.

      Why do you say 'cannot' cannot be used?

        Because I was making a spelling/grammar point, and therefore I was required by law to insert an error.