How do I access values in a Perl Hash of Array of Arrays? -


i have built hash containing arrays of arrays, let's call %hash_multidim, such output data::dumper looks so:

      'key1' => [                    [                      '-3.81',                      '-1.91',                      '-1.86',                      '-1.70'                    ],                    [                      '1.35',                      '1.04',                      '-1.01',                      '-2.69'                    ]                  ],       'key2' => [                     [                       '-1.63'                     ],                     [                       '-1.17'                     ]                   ], 

now, access , perform manipulations on bottom-most level in structure. example, 'key1' want find mean of in row 1 (aka mean of array @ [0]). using list::util qw(sum), have written subroutine called mean:

sub mean {     return sum(@_)/scalar(@_); } 

however, if using subroutine, eg:

my $test = mean($hash_multidim{key1}[0]); print $test; 

i not expect. in fact, get:

43678288 

where did go wrong? if try evaluate result of

$hash_multidim{key1}[0] 

everything looks kosher. e.g.,

@test2 = $hash_multidim{key1}[0]; print dumper(\@test2); 

produces output:

$var1 = [           [             '-3.81',             '-1.91',             '-1.86',             '-1.70'           ]         ]; 

$hash_multidim{key1}[0] array reference, mean expects list. need "dereference" it. syntax little tricky, is

my $test = mean( @{$hash_multidim{key1}[0]} ); 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -