in reply to Re: Re: Another Array Problem.
in thread Another Array Problem: comparing.
foreach($_) is kind of useless, you can safely remove it (and its closing bracket, of course).foreach($_){
You don't have to name everything. Instead, you can assign to undef if you don't need a specific value.my ($num,$date,$time,$fw,$type,$action,$alert,$int,$dir,$proto,$src +,$dst,$service,$sport,$len,$rule) = (split /;/,$_);
Because there are more undefs than used values, a list slice would be even better:my (undef, undef, undef, undef, undef, undef, undef, undef, undef, +undef, undef, $dst, $service, undef, undef, undef) = split /;/; # spl +it() works on $_ if only one argument is given.
my ($dst, $service) = (split /;/)[11, 12];
There's no need to use these temporary variables %hash and $val;%hash = (dest => $dst, service => $service); foreach my $key (keys %hash){ my $val = $hash{$key}; $count{$val}++; } #close foreach } #close while
$count{$_}++ for $dst, $service; }
This can be done using map, but it might be confusing if you don't know how it works:foreach my $key1 (keys %count){ print "$key1 appears $count{$key1} times\n"; } #close foreach
print map "$_ appears $count{$_} times\n", keys %count;
Please also note I have a whitespace after every comma, which in my opinion makes the source more readable.
I hope this was useful to you
As a whole:
|
|---|