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");
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.