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
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.