in reply to Creating a hash of arrays from DB results

O(1) memory solution (provided the results are grouped by stamp):

my $last; my $count = 0; while (my $row = $sth->fetch()) { my ($stamp, $status) = @_; if (defined($last) && $last ne $status) { print("$last: $count\n"); $count = 0; } $last = $stamp; ++$count if $status eq 'In Use'; } print("$last: $count\n") if defined($last);