If the count is all you need, you don't need of %hash at all: my %count;
while (<FILE>){
next unless /something/;
if (/<LONG REGEX>/){
$count{$3}++ if $3;
}
}
If McDarren is correct, and you want to keep track of all items, you should probably maintain an array inside $hash{$3} (and a variable rename would be good in this case), and in this case you would have the count "for free", just looking at how many elements each item has:
my %hashes_for; # More sensible name
while (<FILE>){
next unless /something/;
if (/<LONG REGEX>/){
push @{$hashes_for{$3}}, {
sig => $1,
src => $3,
proto => $2,
dst => $4,
port => $5,
};
}
}
# You can now use scalar(@{$hashes_for{whatever}}) instead of $count{w
+hatever}
Note: untested code!
Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf
Don't fool yourself.
|