I have a hash table with the following contents:
my %hash = (
'a' => 1,
'b' => 2,
'c' => [3, 4, 5],
);
And later on I’m pulling $hash{'c'} into @array_c as part of fetching function such as:
sub getVar {
my $id = shift;
return $hash{$id};
}
my @array_c = getVar('c');
Then later on I’m attempting to loop through @array_c and print each line:
foreach (@array_c){
print "$_";
}
However instead of the desired output of 345, I get ARRAY(0x100804ed0)
Please help 😀
EDIT:
If I do print @array_c[0]->[0] then I get 3, so I guess I’m a little confused as to how I’ve managed to create a nested array.
SOLVED:
Went with deferencing the array:
my @array_c = @{getVar('c')};
The
sub getVarreturns a refrence to an array, just dereference it:or change the sub: