in reply to Re^2: How to write a utf-8 file
in thread How to write a utf-8 file
Consider what happens if the file doesn't exist:
In your original code, things will go wrong with no explanation.
In the suggested alternative, the code will print "can't open UTF-8 encoded filename: File Not Found" and then exit safely.
Depending on the specific problem, $! could be file not found, permission denied, out of disk space, locked by another process, etc... whatever reason the OS gives. Extremely helpful!
You're already using the 3-arg version of open, which is good. You can add lexical file handles ($inFH rather than just IN), checking the return value (the "||", or better yet, "or"), and printing $! when things do go wrong. These are all good habits to get into, as they will help you avoid debugging pain in the future.
|
|---|