Reputation: 928
I have the following perl code which tries to write a string to a newly created file:
open(OUT, ">$file") or die "file out error!\n";
print OUT $string;
Normally, this code works fine. If we do not have write permissions to the directory where $file exists, the program fails, which is expected. However, instead of printing "file out error!" as the error message, the program simply exits with exit code 13 (Permission denied).
Upvotes: 2
Views: 1172
Reputation: 7516
I think you are confusing the programs exit code and its reporting of a standard system system error code. Error code (errno
) 13 equates to "permission denied".
perl -lE '$!=13;say $!'
Permission denied
perl -lE '$!=32;say $!'
Broken pipe
Of course the actual message may vary slightly depending on your OS.
And for that matter, a better (IMO) way to construct an error message for the open is something like: `open OUT,">","$file" or die "Can't open $file: $!\n".
Upvotes: 3