in reply to Re^3: unquoted string error??!!
in thread unquoted string error??!!

Here is my (humble) opinion on why it is best to avoid bareword file handles...
Yeah, let's avoid reading from STDIN, or avoid writing to STDOUT or STDERR. Or make use of the magical handles DATA or ARGV.

As long as the three most important filehandles (important enough that by default (at least on Unix), all processes will have them) are bare file handles, I cannot stop thinking "uttered by someone with limited knowledge of Perl" when hearing advice like "is best to avoid bareword file handles".

As for you example bug; first of all, your use of warnings would have caught any typos in filehandle names - close OUTPUT_FH generates the warning Name "main::OUTPUT_FH" used only once: possible typo at: .... Furthermore, the above does have a serious bug: it's not checking the return value of closed. If it did, it would have notices the failure of closing a handle that wasn't opened.

Replies are listed 'Best First'.
Re^5: unquoted string error??!!
by runrig (Abbot) on May 05, 2011 at 15:57 UTC
    Yeah, let's avoid reading from STDIN, or avoid writing to STDOUT or STDERR.

    Oh, c'mon. Oversight due to generalization, updated post.

    And to your other points: Yes, warnings are easy to notice in programs with very little output. And as noted elsewhere, there may or may not have been only a 'used once' warning in the actual code. And whether or not you catch the error in closing a handle that's already closed, it's better to catch the error at 'compile' time rather than runtime. Also note, "IT'S NOT MY CODE", and I consider myself lucky if others check the return value of open and include $! in the error message. If they start checking the return value of close, I might die of shock.