You guys are the best. It now works, and fast too. Thank you. Kevin
From: Bob Showalter <[EMAIL PROTECTED]>
To: 'kevin r' <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
Subject: RE: Sorting Help!!!
Date: Thu, 30 Jan 2003 14:20:09 -0500
kevin r wrote:
> Rob,
>
> I believe that you are correct in that there is an
> alternative answer.
> Without posting a long script, here is the premise:
>
> while logfile {
> if (certain conditions are met)
> push @portArray, $_ ## pushes certain elements of the $_ into array,
> protocol and port number
>
> The array will look like the following:
>
> 80 TCP
> 443 TCP
> 137 UDP
> 80 TCP
> 80 TCP
> 25 TCP
> .
> .
> .
>
> This becomes a very long list. From here I would sort and then
> sequentially step through the array. If the current line does not
> look like the last line the print the last line and the number of
> times it was counted. The output looks as follows:
>
> TCP 80 - 25
> TCP 443 - 32
> TCP 25 - 837
> UDP 137 - 23
>
> That logic was based on the sort function. Any help would be great,
> I have a couple of ideas to make it faster that I am going to try.
Use a hash to accumulate the statistics. Something along these lines:
my %stats;
while(<LOGFILE>) {
my ($proto, $port) = ... extract protocol and port from $_ somehow ...
$stats{"$proto $port"}++;
}
print "$_ = $stats{$_}\n" for sort keys %stats;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]