More generic than haukex's, more pure-perl than Athanasius's, more functional than OO
Shorter than huck's ;-P
sub count { my ($data, $fields) = @_; $fields = [$fields] unless ref $fields; my $count = {}; for my $obj (@$data) { my $ref = $count; $ref = $ref->{ $obj->{ $fields->[$_] } } //= {} for 0..$#$fields-1; $ref->{ $obj->{ $fields->[-1] } }++; } return $count; }
(For input, output and other context see my other node)
In reply to Re^2: SQL like query over iterable in perl
by haukex
in thread SQL like query over iterable in perl
by pwagyi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |