You've got a hash of hashes (sometimes called HoH) here - basically, %srciphash is a hash (an associative array) that contains references to further hashes.

The first line you merely records whether a connection was made from a given source to a given destination ip (assuming that's what "srcip" and "dstip" stand for, which I think is pretty likely), by setting the appropriate element of the appropriate hash (itself an element in %srciphash) to 1.

The second line later on iterates over all the source ips gathered; for that, the hash keys (the source ips) are extracted from the hash via the keys operator, and fed to a foreach loop which iterates over them one by one, assigning each of them to $srcip for the duration of the loop.

The third line is quite similar to the second; an iteration over the keys of a hash (the destination ips for a given source ip this time) is made again, and the only real difference is that the hash these come from needs to be obtained first. In other words - since $srciphash{$srcip} (the hash value associated with the given source ip in %srciphash) is itself a reference to a hash (and thus a scalar value) instead of an immediate hash, it needs to be made into a hash again first for the keys operator to be able to work on it; that's simply done by prepending a % (and wrapping the whole thing in curly braces to avoid ambiguities). Then, a foreach loop is used again to iterate over all the destination ips for the given source ip (the keys of the hash that is the value associated with the source ip in %srciphash), so, in effect, the two nested loops just iterate over all pairs of src and destination ips that were encountered found earlier on.

The actual value stored (the 1) is not used - it could've been any value really, too, as it just serves the purpose of making sure the given *key* actually exists in the hash.

Hope this helps! :)

--
mowgli


In reply to Re: wondering what exactly these lines does by mowgli
in thread 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.