Hello Monks,

I'm trying to assign the values from a couple of 2-D Arrays into a hash based on a "key" within the array.
I haven't messed with hashes in a while so I'm a little rusty. I'm having trouble figuring out how to assign the values, I looked for an example online but alas Google has failed me lol...

What I have is 5 separate 2-Dimensional Arrays. All arrays have the same setup.
For Example: @myArray[key][value]
### I'm using 5 separate arrays but for the sake of space I'll just do + 3 here... $first[0][0] = "111" $first[0][1] = "on" $first[1][0] = "222" $first[1][1] = "off" $first[2][0] = "333" $first[2][1] = "null" ...etc... ############################ $second[0][0] = "111" $second[0][1] = "10.1.1.1" $second[1][0] = "222" $second[1][1] = "12.1.1.1" $second[2][0] = "333" $second[2][1] = "13.1.1.1" ...etc... ############################ $third[0][0] = "111" $third[0][1] = "12.1(SAG1)" $third[1][0] = "222" $third[1][1] = "12.4(FCL5)" $third[2][0] = "333" $third[2][1] = "12.1(5)" ...etc... ############################ ### Then have a hash with all the values combined. # i.e. the hash should look something like this after a 'Data::Dump': #--------- %all_data ---------# VAR1 = '111' => "on", => "10.1.1.1", => "12.1(SAG1)"; VAR2 = '222' => "off", => "12.1.1.1", => "12.4(FCL5)"; VAR3 = '333' => "null", => "13.1.1.1", => "12.1(5)";

I'm having trouble figuring out if I need a loop or what not, because not all the arrays are the same length.
Occasionally a couple of the arrays might have more than one value for a particular key...
i.e. It might have 2 values like this below for the key "111".
$fourth[111][125]
$fourth[111][200]


If anyone has any hints that could point me in the right direction that would be great...
I've read the PerlDocs on hashes but I am still a little confused.


Thanks in Advance,
Matt


In reply to Assign 2D-Arrays to a hash using a key by mmartin

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.