elofland:

Just a couple minor notes:

  1. Perl automatically creates hash table entries for you if you reference them, so you don't need to explicitly create them. (Search for "autovivification" for details.)
  2. Perl treats an undef as a numeric 0 when you increment the value.

Example:

#!/usr/bin/perl -w use warnings; use strict; my %topHash; # (1) Perl automatically creates the hash table entries as needed # (2) The undef value will be treated as zero, so the result of this # statement is that $topHash{77}{15}{Feb} is 1 ++$topHash{77}{15}{Feb}; for my $k1 (keys %topHash) { for my $k2 (keys %{$topHash{$k1}}) { for my $k3 (keys %{$topHash{$k1}{$k2}}) { print "$k1 / $k2 / $k3 : '$topHash{$k1}{$k2}{$k3}\n"; } } }

So you can simplify the first chunk of your code to:

... while (<FILE>) { my $line=$_; (my $day,$month,$year,$hour,$minute) = ( $line =~ /^.*\[(\d*)\/(.*) +\/(\d*):(\d*):(\d*).*$/); ++$topHash{$year}{$month}{$day}{$hour}{$minute}; } close(FILE);

...roboticus


In reply to Re: hash of hash of hash of hash of hash... by roboticus
in thread 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.