my %interfaces = ( R1R0 => 1, R1R6 => 2, R2R0 => 3, R2R6 => 1, R3R61 => 2, R3R62 => 3, ); push (@routers, $r[1],$r[2],$r[3]); foreach my $rh (@routers) { $rh->config(" deactivate $interfaces{$R1R0}"); }

In the above code, there are 6 interfaces, 2 from each router, (R1, R2, R3). I want to deactivate each interface as defined in hash from all the routers. For that, am doing a foreach (to get the router handles separately), and execute the action. The problem with this is, when foreach executes the first router, say $r[0], only the first interface (defined in hash/key as R1R0) is executed. I want to execute both (first and second hash/key pair for R1), when foreach is executed for $r[0], similarly for R2 and R3. I found the only way is defined a seperate hash for all the three routers as below

%interfaces_R1 = ( R1R0 => R1R6 => ); %interfaces_R2 =( ...

Is there a better way to do it


In reply to Hash key & foreach 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.