I'm new to Perl, and have been doing some reading and going thru some scripts we use here at work, and came across something that neither my reference book (Core Perl, by Reuven M. Lerner) addresses, nor my co-workers know exactly what it seems to do.

$srciphash{$srcip}{$dstip} = 1;

This is nested inside of a while loop, and no other action within the loop acts on srciphash. The $srcip and $dstip scalars are assembled from array elements earlier in the loop. I'm confused because I'm not exactly sure what it's doing.

After the while loop is done, this loop is started:

foreach $srcip (keys(%srciphash))

and within this loop, another loop is nested:

foreach $dstip (keys(%{$srciphash{$srcip}}))

Can anybody explain to me exactly what those 3 lines are supposed to mean? I'm hoping that I'm not the only Perl newb who's having trouble get a handle on the concept of hashes.

update (broquaint): title change (was wondering what exactly these lines does)


In reply to nested hashes and their usage e.g $foo{bar}{baz} by Chris_LSU

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.