I have built a hash containing arrays of arrays, let's call it %hash_multidim, such that the output from Data::Dumper looks like so:
'Key1' => [
[
'-3.81',
'-1.91',
'-1.86',
'-1.70'
],
[
'1.35',
'1.04',
'-1.01',
'-2.69'
]
],
'Key2' => [
[
'-1.63'
],
[
'-1.17'
]
],
Now, I would like to access and perform manipulations on the bottom-most level in this structure. For example, for 'Key1' I want to find the mean of the in row 1 (aka the mean of the array at [0]). Using List::Util qw(sum), I have written a subroutine called mean:
sub mean {
return sum(@_)/scalar(@_);
}
However, if using the subroutine, eg:
my $test = mean($hash_multidim{Key1}[0]);
print $test;
I do not get what I expect. In fact, I get:
43678288
Where did I go wrong? If I try to evaluate the result of
$hash_multidim{Key1}[0]
everything looks kosher. E.g.,
@test2 = $hash_multidim{Key1}[0];
print Dumper(\@test2);
produces this output:
$VAR1 = [
[
'-3.81',
'-1.91',
'-1.86',
'-1.70'
]
];