There are a couple ways you could go with this. One would be to create a hash of arrays. So the hash key '111' would point to an array containing 'on', '10.1.1.1', and '12.1(SAG1)', for example.

However, since you said some keys may have multiple values for some positions, that may be too restrictive. So another method would be to create a hash of hashes, keying the secondary hashes with whatever keys fit your data. For example:

my %hoh = ( '111' => { switch => 'on', ip => '10.1.1.1', version => '12.1(SAG1)'}, '222' => { switch => 'off', ip => '12.1.1.1', version => '12.4(FCL5)'}, '333' => { switch => 'null', ip => '13.1.1.1', version => '12.1(5)'}, ); # $hoh{333}{switch} = 'null';

By doing it this way, it doesn't matter if a key doesn't have a 'switch' value, for instance; it won't throw off the rest of the array. And if a particular sub-key may have multiple values, you can give it an array of its own, like so:

'333' => { switch => 'null', ip => ['13.1.1.1','13.2.2.2','13.3.3.3'], version => '12.1(5)'},

Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.


In reply to Re: Assign 2D-Arrays to a hash using a key by aaron_baugher
in thread 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.