in reply to idiom for building hash of arrays?
The idiom you are looking for isuse strict; use warnings; use List::MoreUtils qw/zip natatime/; use Data::Dump qw/dump/; my @keys = qw {red blue red}; my @vals = (1, 2, 3); my %hash; my $it = natatime 2, zip @keys, @vals; while (my ($key, $value) = $it->()) { push @{$hash{$key}}, $value; } print dump(\%hash);
push @{$hash{$key}}, $value;
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|