Perl 错误地抱怨 Name "main::FILE" used only once
Perl wrongly complaining about Name "main::FILE" used only once
我将我的程序简化为以下琐碎的片段,但我仍然收到消息
Name "main::FILE" used only once: possible typo...
#!/usr/bin/perl -w
use strict;
use autodie qw(open close);
foreach my $f (@ARGV) {
local $/;
open FILE, "<", $f;
local $_ = <FILE>; # <--- HERE
close FILE;
print $_;
}
这显然不是真的,因为它被使用了三次。无论出于何种原因,只有标记的出现才算数。
我知道打开文件的更好方法(使用 $filehandle),但它不会为短脚本付费,是吗?那么我怎样才能摆脱错误的警告呢?
根据 documentation 对于 autodie
:
BUGS
"Used only once" warnings can be generated when autodie or Fatal is used with package filehandles (eg, FILE ). Scalar filehandles are strongly recommended instead.
我在 Perl 5.10.1 上收到警告,但在 5.16.3 上没有,所以可能还有其他原因。
我将我的程序简化为以下琐碎的片段,但我仍然收到消息
Name "main::FILE" used only once: possible typo...
#!/usr/bin/perl -w
use strict;
use autodie qw(open close);
foreach my $f (@ARGV) {
local $/;
open FILE, "<", $f;
local $_ = <FILE>; # <--- HERE
close FILE;
print $_;
}
这显然不是真的,因为它被使用了三次。无论出于何种原因,只有标记的出现才算数。
我知道打开文件的更好方法(使用 $filehandle),但它不会为短脚本付费,是吗?那么我怎样才能摆脱错误的警告呢?
根据 documentation 对于 autodie
:
BUGS
"Used only once" warnings can be generated when autodie or Fatal is used with package filehandles (eg, FILE ). Scalar filehandles are strongly recommended instead.
我在 Perl 5.10.1 上收到警告,但在 5.16.3 上没有,所以可能还有其他原因。