Here is my (humble) opinion on why it is best to avoid bareword file handles...(Update: except for STDIN, STDERR, DATA, ARGV, and the like...)
While it doesn't matter in a situation as simple as in the OP, in a non-trivial situation, if you use a lexical file handle (and 'use strict'), you can avoid the following bug:
This exact sort of thing happened here@work, where there is a serious lack of lexical file handle use, and took a non-zero amount of time to debug. It also failed to influence anyone's decision in choice of file handle type :-(#!/usr/bin/perl use strict; use warnings; my $file = "file.txt"; CreateFile($file); system frobnicate => $file; sub CreateFile { my $f = shift; open(OUTPUT_FILE, ">$f") or die "Err: $!"; for (1..100) { print OUTPUT_FILE "$_\n"; } # blah, blah, blah... close OUTPUT_FH }
In reply to Re^3: unquoted string error??!!
by runrig
in thread unquoted string error??!!
by aji
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |