Note: I don't know anything about NDMB_File, so I'm working with the structure you showed.

For starters, Data::Dump is your debugging friend here:

use Data::Dumper; print(Dumper(\%db));

To move around your structure, have a look at these two snippets:

foreach $key (keys(%db)) { for ($record_num=0; $record_num<@{$db{$key}}; $record_num++) { foreach $field (@{$db{$key}[$record_num]}) { printf("Record %d of %s is %s.\n", $record_num, $key, $field, ); } } }
foreach $key (keys(%db)) { foreach $record (@{$db{$key}}) { foreach $field (@$record) { ... } } }

To append a record to a given key,

# From ref to array of fields: push(@{$db{$key}}, $record); -or- # From individual fields: push(@{$db{$key}}, [ $field1, $field2, $field3, $field4 ]); -or- # From a my'd array of fields: { my @fields = ...; push(@{$db{$key}}, \@fields); } -or- # From a array of fields that will change: push(@{$db{$key}}, [ @fields ]);

Comma-delimited:

# Gives: # key1,field1,field2,field3,field4 # key1,field1,field2,field3,field4 # key1,field1,field2,field3,field4 # key2,field1,field2,field3,field4 # key3,field1,field2,field3,field4 # key3,field1,field2,field3,field4 # # Doesn't handle commas in key or field. $,=','; $\=$/; foreach $key (keys(%db)) { foreach $record (@{$db{$key}}) { print $key, @$record; } } -or- # Gives: # key1,0,field1,field2,field3,field4 # key1,1,field1,field2,field3,field4 # key1,2,field1,field2,field3,field4 # key2,0,field1,field2,field3,field4 # key3,0,field1,field2,field3,field4 # key3,1,field1,field2,field3,field4 # # Doesn't handle commas in key or field. $,=','; $\=$/; foreach $key (keys(%db)) { for ($record_num=0; $record_num<@{$db{$key}}; $record_num++) { print $key, $record_num, @{$db{$key}[$record_num]}; } }

In reply to Re: Hash of arrays of arrays by ikegami
in thread 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.