Not sure if this will get you any closer, but here is my take. I changed the way values are gotten from using 'substr' to captures from a regular expression (if that would work).

I formatted $hour to have a leading '0', if necessary, using the sprintf function.

There are 2 hashes: one for accumulating the daily totals and one for accumulating the hourly stats.

my %daily_total; my %hourly_stats; while (<DATA>) { # looking for: 06/05/2008 8:31a if (m{\d\d/(\d\d)/\d{4}\s{1,2}(\d+):(\d\d)(a|p)}) { my $day = $1; # get day my $hour = sprintf "%02d", $2; # get hour my $minute = $3; # get minutes my $ampm = $4; # get am or pm if ($ampm eq "p" && $hour != 12) {$hour += 12; } $hour = '00' if $ampm eq "a" && $hour == 12; $daily_total{$day}++; $hourly_stats{$day}{$hour}{total}++; if ($minute <= 29) { $hourly_stats{$day}{$hour}{HalfHour00}++; } else { $hourly_stats{$day}{$hour}{HalfHour30}++; } } } for my $day (sort keys %daily_total) { print "day: $day, total: $daily_total{$day}\n"; for my $hour (sort keys %{ $hourly_stats{$day} }) { print "hour: $hour\n"; print " first 1/2 hr: ", $hourly_stats{$day}{$hour}{HalfHour +00}|| 0,"\n"; print " second 1/2 hr: ",$hourly_stats{$day}{$hour}{HalfHour +30}|| 0,"\n"; print " total/hour: $hourly_stats{$day}{$hour}{total}\n"; } print "\n"; }
Chris

Update: A change to output routine to correct error found using dataset provided by johngg.


In reply to Re: Brain muchly befuddled by nested hashes by Cristoforo
in thread Brain muchly befuddled by nested hashes by WartHog369

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.