Dear Perl Monks,

Please help out a relatively novice Perl devotee, with a problem which has been driving me nuts for the past few days:

I am trying to implement a tied NDMB_File hash, where each hash key can reference 1 - n records, each consisting of several fields. The obvious structure seems to be a hash, with each key referencing an array of records, and each record referencing an array of fields - a hash of arrays of arrays, in other words. Conceptually, I guess it would be something like this:

%db -> key1 -> [ [field1, field2, field3, field4] [field1, field2, field3, field4] [field1, field2, field3, field4] ] -> key2 -> [ [field1, field2, field3, field4] ] -> key3 -> [ [field1, field2, field3, field4] [field1, field2, field3, field4] ]
It seems like it should be do-able. However, I don't have much experience with hashes and references, and I can't seem to figure out how to access the elements correctly. Every time I start to think that I am storing the data correctly, I find that I still can't retrieve it! Consequently, I am not going to post any of my code, as at this point I don't trust any of it!

I need to be able to add and retrieve records, compare records, and loop through the entire hash to generate a comma-delimited dump of the database.

I would be deeply grateful for any assistance that the Monks could give me with this.

Thanks in advance for any help!

Graham Scott.

In reply to Hash of arrays of arrays by Anonymous Monk

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.