David Green David Green - 3 months ago 18
Perl Question

Perl - Global symbol requires explicit package name

I am calling a perl subroutine

&ProcessInput($line, \%txcountershash, \%txhash);


I have this definition:

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};


the line that causes the problem is the last line. It says that global symbol %countershash requires explicit package name. I'm not sure why it's giving me the error. There aren't any problems otherwise, if I comment that line out the script runs. The hash is set up as an error code for a key and a description that is the value. I'm trying to get the value at a particular key in $countershash so I can add the error description to the output hash.

Answer

The problem is dereferencing. you should dereference the hash inside the subroutine

my $counterdesc = $$countershash{$counter};
Comments