【发布时间】:2016-08-19 16:49:18
【问题描述】:
我正在调用一个 perl 子例程
&ProcessInput($line, \%txcountershash, \%txhash);
我有这个定义:
sub ProcessInput() {
my $word;
my $counterkey;
my $line = $_[0];
my $countershash = $_[1];
my $outputhash = $_[2];
# remove all the blanks from the line
$line =~ s/\s+//g;
my ($port,$counter,$value,$datetime) = split('\|',$line,4);
my $counterdesc = $countershash{$counter};
导致问题的行是最后一行。它说全局符号 %countershash 需要明确的包名。我不确定为什么它给了我错误。否则没有任何问题,如果我注释掉脚本运行的那一行。哈希被设置为键的错误代码和作为值的描述。我正在尝试获取 $countershash 中特定键的值,以便可以将错误描述添加到输出哈希中。
【问题讨论】:
-
另外,不再需要在函数调用的前面加上
&。 -
对不起。澄清。它在抱怨 %countershash。我意识到我错误地删除了定义 $counter 的行
-
叫它
$countershash->{$counter} -
Perl 抱怨一个名为
%countershash的散列,您没有定义它,而是有一个名为$countershash的散列引用。 -
啊。谢谢。这是有道理的。
标签: perl