Hi,

I have succesfully produced a data structure for a project at work, but I can't loop (traverse) through it so as to print it out!

The data structure is a hash of hashes of hashes. It looks like this:

%customers = (); $customers{$acct_id}{$ip}{'variableName'} = 'valueForVariable';
Basically, I have a few variables at the ip address level. $acct_id specifies accounts. Each account has a bunch of ip's. I have an array that holds every account ID. So, I want to do be able to loop through the hash for every ip at each given value for acct_id, so that I can print out the ip and various variable values, such as an snmp community read setting.

Does anyone know how I can traverse through such a data structure? I need to do so by iterating through the array that contains the account id's.

Here is an additional thing. I populated the data structure by passing a reference to it in a subroutine. I have no reason to do this here part in a subroutine, but I would be curious how to traverse through this data structure in two ways. One, by specifying the data structure directly. Two, by specifying it with a pointer to it.

As for me, I googled looping through hashes of hashes and perused this wonderful site, but didn't find anything that showed me how. I've made a number of attempts and remain pretty stuck.

Thanks in advance...

Tony (o2)

In reply to traversing through a (complex for me) data structure by o2bwise

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.