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]