The question that keeps niggling me is: Why do you want an array at that point?

Arrays are indexed numerically, and 'year' is not numeric. And if 'year' is a placeholder for 1999, 2000, 2001 etc., then I still don't understand why you want an array. Array's start from 0 (ignoring $[ which is totally impractical), which unless your application needs to deal with antiquity, means that you'll be reserving (a relatively small amount) of space for almost 2000 entries in each 'date' array that you will never use.

Remember, that's one array for every 'galaxy' * 'solar system' * 'planet'; depending upon the size of your universe, that adds up to a lot of dark matter wasted space :)

The advantages of arrays over hashes for numeric data are:

  1. They are slightly faster
  2. They use less memory

If you are only using indexes 2000 .. 2020 of 0 .. 2020, then you will pretty much completely negate the latter, and the former is unlikely to make any appreciable difference given that you are already doing 5 other levels of hash lookup. Stick with a HoHoH(oH...)--it will make your life much simpler. You might look at YAML for your multi-dimensional configuration data. It seems to be the simplest/clearest format for manually maintained data.

Finally, for contrast with Zaxo's advice--for the purpose of giving the ammunition to make up your own mind--compare iterating all the latitudes and longitudes for a given year and incrementing the number of occurances:

Using a HoH:

my $thisYear = 2005; my $yearRef = $galaxy{ $sSystem }{ $planet }{ $thisYear }; for my $year ( keys %{ $yearRef } ) { for my $lat ( keys %{ $yearRef->{ $year } } ) { for my $long ( keys %{ $yearRef->{ $year }{ $lat } } ) { printf "$sSystem.$planet.$thisYear.$lat.$long:%s\n", $yearRef->{ $year }{ $lat }{ $long }; $yearRef->{ $year }{ $lat }{ $long }++; } } }

Using OO:

my $thisYear = 2005; my $yearIter = $galaxy->getYearIerator( $sSystem, $planet, $thisYear ) +; while( my $year = $yearIter->() ) { my $latIter = $year->getLatitudeIter(); while( my $lat = $latIter->() ) { my $longIter = $lat->getLongIter(); while( my $long = $longIter->() ) { printf "$sSystem.$planet.$thisYear.%s.%s.%s\n", $year->getYear(), $lat->getLat(), $long->getLong(), $long->getOccurances(); $long->setOccurances( $long->getOccurances() + 1 ); } } }

Your choice ;)


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Hierarchial data structures by BrowserUk
in thread Hierarchial data structures by Q3Man

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.