我打電話一個Perl子的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中特定鍵的值,以便將錯誤描述添加到輸出哈希。
此外,不再需要在函數調用的前面加上'&'。 – xxfelixxx
對不起。澄清。它抱怨%反擊。我意識到我已經刪除了錯誤定義$ counter的行 –
將它稱爲'$ countershash - > {$ counter}' – xxfelixxx