I have this really annoying problem that I can't seem to figure out... I need to create a hash that contains two sets of arrays embedded. Editting the array in the hash would look like this:

$db{'key1'}{'key2'}[0][0] = "one_value"; $db{'key1'}{'key2'}[0][1] = "two_value"; $db{'key1'}{'key2'}[1][0] = "three_value"; $db{'key1'}{'key2'}[1][1] = "four_value"; $db{'key1'}{'key2'}[2][0] = "three_value"; $db{'key1'}{'key2'}[2][1] = "four_value";

Or maybe like this, I'm not sure:

@{$db{'key1'}{'key2'}[0][0]} = "one_value"; @{$db{'key1'}{'key2'}[0][1]} = "two_value"; @{$db{'key1'}{'key2'}[1][0]} = "three_value"; @{$db{'key1'}{'key2'}[1][1]} = "four_value"; @{$db{'key1'}{'key2'}[2][0]} = "three_value"; @{$db{'key1'}{'key2'}[2][1]} = "four_value";

Now, under the key2 key, I don't know how many values are in that array. (The first set of array numbers, namely 0, 1, and 2). The second set of array numbers (The constant 0 and 1) are always there and only have the indexes 0 and 1.

Could someone please give me an idea what this hash structure would look like, and how I would go about getting the last index number of the first set of array numbers. (Something like $#{$db{'key1'}{'key2'}} maybe?)

And also, how would I go about deleting the array? I don't want to do delete $db{'key1'}{'key2'}, but something more along the lines of  delete $db{'key1'}{'key2'}[3].

Thanks ahead of time!


In reply to Array in a Hash by mt2k

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.