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).
- Why does the open method succeed when we are unable to write to the file?
- How do we get the appropriate error message in this instance?