You are "Suffering from Scoping". (As well as two rather nasty side-effects of references, but those'll get fixed.)

Let's diagram what you're doing with @cname. You've declared it at the top of your program. This implies that you are attempting to gather together a list of computer names from across your entire file. This doesn't sound like what you want to do.

Instead, you want to gather a list of the computer names for a given IP address. Again, you're almost there.

push @{$data{$ip}{cname}}, $1 if /\b$ip\b\s{2,}(\w[^\s]*|\[Unknown\])\s{2}/; push @{$data{$ip}{ports}}, $1 if /((\d{1,5}?)\s{2}(\w[^\n]*))\s{2}/; push @{$data{$ip}{banners}}, $1 if /\Q|___\E\s+([^"]*)\.{1,3}\s+\n/;
This way, you're doing the pushing onto the array you actually want. (Obviously, you remove the declaration of @cname and his friends, cause it's not needed anymore. You also remove the hash-slicing cause it's also not needed anymore.)

For your personal edification, what was happening was that you were creating one array - @cname. Every instance of your data was referencing this specific array. Every time you modified it, each instance would know about the modifications. Every time you de-referenced it, you were de-referencing the same array.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.


In reply to Re3: Which Data Structure Should I Be Using? by dragonchild
in thread Which Data Structure Should I Be Using? by dru145

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.