in reply to mutiple array as hash value per key

The values in a hash can be any kind of scalar. To get the results that you want, each value would need to be a reference to an array, and each element in the referenced arrays would need to be another array reference.

%number = ( 23 => [ [ 'g1', 23, 24 ], [ 'g2', 34, 35 ] ], 24 => [ [ 'g3', 45, 56 ], [ 'g4', 36, 48 ] ], ); $grp = $number{23}[0][0];

Note the I've corrected your hash-creating brackets from {} to ().

For more details see perldsc.

--

See the Copyright notice on my home node.

Perl training courses

Replies are listed 'Best First'.
Re^2: mutiple array as hash value per key
by Anonymous Monk on Jul 02, 2009 at 06:44 UTC
    in case i have new set of data (new array) referring to same key,is it possible to push the array value to the hash? eg :
    new set is read from a file while ($line <>){ ($key,$value)=split(/,/,$line); #suppose #line have 23,['g8',23,45] push @{$numbers{23}},$value; }
    will this append the new array to existing key ?

      What you're looking for is probably more like:

      while (<>) { chomp; my ($key, @values) = split /,/, $_; push @{$numbers{$key}}, [ @values ]; }

      When playing with complex data structures, perldsc and Data::Dumper are your friend.

      --

      See the Copyright notice on my home node.

      Perl training courses