in reply to Counting items in a CSV

Yup, hashes are great for grouping. But since you have two data points for each date (count and size), you'll need of some kind of 2d structure. I used a hash of hash in the following:
use Text::CSV_XS qw( ); my %size_by_date; my $csv = Text::CSV_XS->new(); while ( my $row = $csv->getline($fh) ) { my ($name, $date, $size) = @$row; ++$size_by_date{$date}{count}; $size_by_date{$date}{size} += $size; } die("csv parse error: " . $csv->error_diag() . "\n") if !$csv->eof(); for my $date (keys %size_by_date) { my ($count, $size) = @{ $size_by_date{$date} }{qw( count size )}; print("$date: $count, $size\n"); }

Replies are listed 'Best First'.
Re^2: Counting items in a CSV
by zyzzogeton (Initiate) on Jun 22, 2009 at 17:21 UTC
    Oh wow. A 2d structure seems so obvious now. I swear I bang my head against the wall sometimes cause it feels so good when I stop.