in reply to Counting items in a CSV
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 |