Perl错误地抱怨名称"main :: FILE";仅使用一次 [英] Perl wrongly complaining about Name "main::FILE" used only once
问题描述
我将程序简化为以下琐碎的代码段,但仍然收到消息
I simplified my program to the following trivial snippet and I'm still getting the message
名称"main :: FILE"仅使用一次:可能是拼写错误...
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 $_;
}
这显然是不正确的,因为它被使用了3次.无论出于何种原因,只有标记的事件才算在内.
which obviously isn't true as it gets used three times. For whatever reason, only the marked occurrence counts.
我知道打开文件的更好方法(使用$ filehandle),但是它不支付短脚本的费用,对吗?那么如何摆脱错误的警告呢?
I am aware about nicer ways to open a file (using a $filehandle), but it doesn't pay for short script, does it? So how can I get rid of the wrong warning?
推荐答案
根据文档对于autodie
:
BUGS
仅使用一次"将autodie或Fatal与程序包文件句柄(例如FILE)一起使用时,可能会生成警告.强烈建议使用标量文件句柄.
"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上没有,所以可能还会发生其他情况.
I get the warning on Perl 5.10.1, but not 5.16.3, so there may be something else going on as well.
这篇关于Perl错误地抱怨名称"main :: FILE";仅使用一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!