elofland has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hash of hash of hash of hash of hash...
by kennethk (Abbot) on Feb 25, 2010 at 22:25 UTC | |
by elofland (Initiate) on Feb 25, 2010 at 22:48 UTC | |
by kennethk (Abbot) on Feb 25, 2010 at 23:03 UTC | |
|
Re: hash of hash of hash of hash of hash...
by almut (Canon) on Feb 25, 2010 at 22:25 UTC | |
|
Re: hash of hash of hash of hash of hash...
by roboticus (Chancellor) on Feb 26, 2010 at 14:32 UTC |