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.
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.)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/;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |