Reputation: 5713
I try to work with hashes in Perl.
I have following example:
my %ERROR_CODE_101 = ("id" => 101,"desc" => "blablabla");
sub checkError
{
# some switch-case
#....
return %ERROR_CODE_101;
}
sub runCommand
{
my $code = checkError();
if($code{id} > 0) # error happens here line 216
{
#...
}
}
Error:
Global symbol "%code" requires explicit package name at build_ios.pl line 216.
Upvotes: 0
Views: 64
Reputation: 943615
my $code = checkError();
assigns the return value to the scalar $code
.
$code{id}
tries to read the scalar id
value from the %code
hash … but you have a scalar, not a hash.
You need to assign the return value to a hash in the first place:
my %code = checkError();
Upvotes: 4