Hi Hena, First things first - my goal is to build a list of MAC_addr->switch_port pairings in "real-time". One can do this with managed switches. Unfortunately I am dealing with layer 2 switches and due to the environment I work in certain Cisco functions must be turned off. The only way to reach my goal, that I've found (even on Cisco's site) is to combine the output of 3 different OIDs. (Assuming you know what an OID is...). Anyway, generally speaking, I end up with 3 hashes: A->B B->C C->D. Thus my post - my end goal is A->D. Also: the following is true; for every A ther is a C, and for every B there is a D, so my perl task is to iterate over every A, match its B with the corresponding C in the second hash, then match that C (key) with its corresponding D (value) in the third hash. (FYI A=MAC_addr, B=bridge port ID, C=ifIndex (Interface Index #) and D=switch_port#). I hope that clarifies at least my goal. To answer your questions - switching the values while inside the while loops is the only way I found to match A->C. I found that when I close the 2 loops, in order, the "matching" logic at the end only sees the last key->value pair in each hash. This is why I wondered if I should be utilizing references instead of playing with the "real" values in memory. (Or I should go ahead and try my original nested loop approach that the monks have officially frowned upon. :) ) Anyway - being my usual verbose self. Thanks, rspence

In reply to Re: Re: Merging 2 hashes - updated again by rspence
in thread Merging 2 hashes - updated again by rspence

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.