kevin r wrote: > 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
Kevin, You don't need an improved sort routine here--you need a better data structure--specifically a b-tree or hash. I prefer b-trees but hashes are built into Perl. When you know that you will receive multiple inputs for a given key, you should never allow the values to be scattered. my %PortAccesses = (); while ($ReportLine = <STDIN>) { my ($Port, $Protocol) = split /,/, $ReportLine; if (condition) { my $PortAccess = $PortAccesses{$Port}; if (!$PortAccess) { $PortAccess = "$Protocol: 0"; } else { my ($ExistingProtocol, $Count) = split /: /, $PortAccess; if ($ExistingProtocol ne $Protocol) {die "mutliple protocols on port $Port\n";} #You'll want #better error handling for this $Count++; $PortAccess = "$Protocol\: $Count" } $PortAccesses{$Port} = $PortAccess; } } Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]