First time poster and new to hash of hashes. I am trying to learn how to navigate around hash of hashes. I have used XML::Simple::XMLin to import a NetCONF (XML) file to $xml. I am trying to print specific parts of the hash, but not with much success using:

print $xml->{'bgp-information'}->{'bgp-peer'}{[0]}->{'peer-address'};

I am also trying to figure out how I can while loop all the "peer-address" entries (e.g. 1.1.1.1, 2.2.2.2, 3.3.3.3) to print entries within. Any input would be greatly appreciated.

Thanks,
~Ethan



$VAR1 = { 'xmlns' => 'urn:ietf:params:xml:ns:netconf:base:1.0', 'bgp-information' => { 'group-count' => '3', 'xmlns' => 'http://xml.juniper.net/juno +s/8.0R3/junos-routing', 'bgp-rib' => { 'total-external-prefix-cou +nt' => '222224', 'damped-prefix-count' => ' +0', 'active-prefix-count' => ' +223534', 'pending-prefix-count' => +'0', 'suppressed-internal-prefi +x-count' => '0', 'active-internal-prefix-co +unt' => '16579', 'name' => 'inet.0', 'junos:style' => 'brief', 'total-internal-prefix-cou +nt' => '69811', 'suppressed-external-prefi +x-count' => '0', 'history-prefix-count' => +'0', 'received-prefix-count' => + '292035', 'active-external-prefix-co +unt' => '206955', 'suppressed-prefix-count' +=> '0', 'bgp-rib-state' => 'BGP re +start is complete', 'total-prefix-count' => '2 +92035' }, 'peer-count' => '3', 'bgp-peer' => [ { 'peer-address' => '1.1. +1.1', 'bgp-rib' => { 'received- +prefix-count' => '69811', 'active-pr +efix-count' => '16579', 'suppresse +d-prefix-count' => '0', 'name' => +'inet.0' }, 'peer-state' => { 'junos: +format' => '16579/69811/0 0/0/0', 'conten +t' => 'Established' }, 'peer-as' => '1000', 'junos:style' => 'terse +', 'heading' => 'Peer + AS InPkt OutPkt OutQ Flaps Last Up/Dwn State| +#Active/Received/Damped...', 'elapsed-time' => { 'juno +s:seconds' => '8579868', 'cont +ent' => '14w1d7h' }, 'route-queue-count' => +'0', 'flap-count' => '0', 'input-messages' => '41 +69581', 'output-messages' => '8 +472027' }, { 'peer-address' => '2.2. +2.2', 'bgp-rib' => { 'received- +prefix-count' => '1', 'active-pr +efix-count' => '1', 'suppresse +d-prefix-count' => '0', 'name' => +'inet.0' }, 'peer-state' => { 'junos: +format' => '1/1/0 0/0/0', 'conten +t' => 'Established' }, 'peer-as' => '2000', 'junos:style' => 'terse +', 'elapsed-time' => { 'juno +s:seconds' => '8580144', 'cont +ent' => '14w1d7h' }, 'route-queue-count' => +'0', 'flap-count' => '0', 'input-messages' => '28 +6000', 'output-messages' => '2 +85903' }, { 'peer-address' => '3.3. +3.3', 'bgp-rib' => { 'received- +prefix-count' => '222223', 'active-pr +efix-count' => '206954', 'suppresse +d-prefix-count' => '0', 'name' => +'inet.0' }, 'peer-state' => { 'junos: +format' => '206954/222223/0 0/0/0', 'conten +t' => 'Established' }, 'peer-as' => '3000', 'junos:style' => 'terse +', 'elapsed-time' => { 'juno +s:seconds' => '7166196', 'cont +ent' => '11w5d22h' }, 'route-queue-count' => +'0', 'flap-count' => '2', 'input-messages' => '84 +23202', 'output-messages' => '2 +38785' } ], 'down-peer-count' => '0' }, 'xmlns:junos' => 'http://xml.juniper.net/junos/8.0R3/junos' };

In reply to Complex Hash of Hashes (New to them) by ewhitt

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.