Hi steph,
in order to solve your problem I recommend you first to look at
hashes of hashes and
autovivification in some perl book.
(For ex. Programming Perl)
Personally, for problems of your kind, I like to use hash references like in the example below:
use strict;
my $hash={};
$hash->{countries}->{USA}->{animals}->{fox}=1560;
$hash->{countries}->{Italy}={};
while ( my ($country, $country_ref) = each %{$hash->{countries}} ) {
print "$country\n";
print $country_ref->{animals}->{fox}."\n"
if exists $country_ref->{animals}->{fox};
};
By building hashes in this way
$hash->{countries}->{USA}->{animals}->{fox}=1560;
I can easily write very complex hash structures
In addition if you look carefully at the example above, you will remark that there is this kind of convention:
metadata->data->'detail metadata'->'detail data'
.
If you do like that you have a single structure to which you can add at any time new dimensions without loosing degrees of freedom.
It shouldnt be too difficult to match this strategy to your actual problem.
Best Regs,
Davide.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.