I think you need to use the syntax that forces types to arrays and hashes. It's in the Hashes of Arrays section of Chapter 9, Data Structures in the Camel book.
my %queries_by_key = (); # Hash of arrays my $number_of_queries = scalar @all_queries; for (my $i = 0 ; $i < $number_of_queries; ++$i) { my %query = %{ pop @all_queries }; # value of pop() is a hash foreach my $query_key (keys %query) { # Treat each value in %queries_by_key as an anonymous array push @{ $queries_by_key{$query_key} }, $query{$query_key}; } } foreach my $key (sort keys %queries_by_key) { print "$key has "; print join ',', @{ $queries_by_key{$key} }; # treat as an array print "\n"; }
I tried to make this clear, but the syntax is kinda confusing. Hopefully they'll explain it better in the book.
Hope this helps,
Chris
In reply to Re: 'group by query' from array of hashes
by chayashida
in thread 'group by query' from array of hashes
by bplegend
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |