Hello perl-brain, I'm very confused about what seems to be a fairly straight-forward thing. My goal is to get a count of hits per minute from apache httpd access logs.

The code speaks louder than my words:

... while (<FILE>) { my $line=$_; (my $day,$month,$year,$hour,$minute) = ( $line =~ /^.*\[(\d*)\/(.*) +\/(\d*):(\d*):(\d*).*$/); if ( defined $topHash{$year}{$month}{$day}{$hour}{$minute} ) { $minuteCounter=$topHash{$year}{$month}{$day}{$hour}{$minute}; $minuteCounter++; $topHash{$year}{$month}{$day}{$hour}{$minute}=$minuteCounter; } else { $topHash{$year}{$month}{$day}{$hour}{$minute}=1; $minuteCounter=$topHash{$year}{$month}{$day}{$hour}{$minute}; } } close(FILE); foreach my $ryear ( sort keys %topHash ) { foreach my $rmonth ( sort keys %{$topHash{$ryear}} ) { foreach my $rday ( sort keys %{$topHash{$ryear}{$rmonth}} ) { foreach my $rhour ( sort keys %{$topHash{$ryear}{$rmonth}{$rd +ay}} ) { foreach my $rminute ( sort keys %{$topHash{$ryear}{$rmonth +}{$rday}{$rhour}} ) { print "\"$ryear\"\t\"$rmonth\"\t\"$rday\"\t\"$rhour\"\t +\"$rminute\"\t"; print "\"$topHash{'$ryear'}{'$rmonth'}{'$rday'}{'$rhour +'}{'$rminute'}\"\n"; } } } } }

The output looks something like this:
"2010"  "Feb"   "11"    "00"    "03"    ""

but, if I put this at the bottom of the script:
print "$topHash{'2010'}{'Feb'}{'11'}{'00'}{'03'}\n";
I get the correct result, in case of my test file:
3

What in the world is wrong with this?
print "\"$topHash{'$ryear'}{'$rmonth'}{'$rday'}{'$rhour'}{'$rminute'}\"\n";
and why oh why will it not work.

advTHANKSance!

-Eric


In reply to hash of hash of hash of hash of hash... by elofland

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.