Q3Man has asked for the wisdom of the Perl Monks concerning the following question:
The data structure needs to be hierarchical and support both hashes and arrays. A quick example of what is needed is:
$galaxy{solarsystem}{planet}[year]{lat}{long}=’foo’;
Now, a simple hash of hashes of hashes… takes care of 95% of the requirements. The problem arises when I want to introduce an array as a parent of a hash. I know I can make a hash (of hashes of hashes) and put a reference to it in the array and be done with it. What I would like to do is eliminate some of that complexity so this data structure can be added to without that additional effort. i.e. the above assignment will fail due to pseudo-hashes being depreciated. (Note: they fail because year is an array. If year is a hash, everything is golden.)
An option that I could use is to simply shorten the depth of a majority of the tree such as:
$galaxy{solarsystem.planet}[year]{lat.long};
But I’m not sure if the added complexity in referencing inside foreach and similar loops is worth any speed improvement. I could combine this with converting the year to a hash and end up with a huge single level hash ($galaxy{solarsystem.planet.year.lat.long}) but that kind of defeats the purpose I’m trying to accomplish in the first place.
So.. I’m looking at what seem to amount to three options. First is to go with straight hashes and make sure array indexes are properly handled (which involves rewriting a non-trivial amount of code, but it is code that will probably need to be rewritten anyway). My second option is to implement the data structures ‘properly’ which may cause some confusion to non-programmers. My third option is to look around for or write a module that can load multi-dimensional hierarchal data from a configuration file (probably exists somewhere).
In order of importance, I want to code this to be:
Anyone have any advice?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hierarchial data structures
by dave_the_m (Monsignor) on May 24, 2006 at 00:19 UTC | |
|
Re: Hierarchial data structures
by Zaxo (Archbishop) on May 24, 2006 at 03:14 UTC | |
|
Re: Hierarchial data structures
by BrowserUk (Patriarch) on May 24, 2006 at 06:54 UTC | |
by Zaxo (Archbishop) on May 24, 2006 at 16:34 UTC | |
by BrowserUk (Patriarch) on May 24, 2006 at 16:52 UTC | |
|
Re: Hierarchial data structures
by NetWallah (Canon) on May 24, 2006 at 04:54 UTC | |
|
Re: Hierarchial data structures
by EdwardG (Vicar) on May 24, 2006 at 08:02 UTC |