Your DBMS returns dates in a known form, say "YYYY-MM-DD", but it's not so good at parsing dates, or you're bloody-minded and want to do it in Perl. You want to generate a calendar, a list of days in each month for which you have entries in your DB (that's not as odd as you think: I came up with this developing an app that lets me see which dates my website got hit, for example)
The problem : your DBMS doesn't grok dates so well. You have a bunch of items (say, events) in a table and you want to know, for any given month, on which days those events occurred. Maybe you want to print out a calendar of some sort, and mark the eventful days. How to represent your data perspciously in Perl? The snippet below will give you, at the end, a hash whose keys are months in the form "MM-YYYY", and whose values are references to arrays that hold the days in that month for which you have entries.
# SQL
#SELECT DISTINCT date FROM hit WHERE location_id = $loc_id
# will get a list back in the form 'YYYY-MM-DD'
my %months;
while (my $row = $sth->fetchrow) {
my ($year, $month, $day) = split '-', $row;
push @{$months{"$month-$year"}}, $day;
}
# cheap print routine to illustrate access to the hash
foreach my $month (keys %months) {
print "For the month of $month, we have events on the following da
+ys :\n";
print "$_ " foreach (@{$months{$month}});
print "\n";
}
Use a module such as HTML::CalendarMonth, and you can quickly create a pretty HTML calendar which you can populate with links, to allow users to see which events occurred on which days.