in reply to hashes with multiple values per key
perldoc perlreftut and perldoc perldsc should be your first stop. Sounds like you want a hash of arrayrefs.
my @keys = qw( a b c ); my @val1 = ( 1, 2, 3 ); my @val2 = ( 2, 4, 6 ); my %hoa; my $idx = 0; for my $k ( @keys ) { @{ $hoa{ $k } } = [ $val1[ $idx ], $val2[ $idx ] ]; $idx++; }
Update: Feh, need more caffeine. As is remarked below it of course should be $hoa{ $k } = [ ... ]. Otherwise you get an extra arrayref around things.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hashes with multiple values per key
by saskaqueer (Friar) on Jan 24, 2005 at 13:40 UTC |