Bizarre Question

Leif Sawyer lsawyer at gci.com
Tue Apr 17 16:38:05 CDT 2001


Aurthur replied:
> On Tue, 17 Apr 2001, Leif Sawyer wrote:
> 
> > What I'm trying to do, is print out a list of ports, by protocol,
> > for each ACL.  And i'd like the ports sorted by the number 
> > of packets, descending.
> 
> To just sort it by acl, protocol, and packet count, in that 
> order, something
> like this would do:
> 
> foreach $acl (keys %data) {
> 	foreach $proto (keys %{$data{$acl}}) {

###### this block is all i care about right now:

> 		foreach $port (sort { $data{$acl}{$proto}{$b} <=> 
> 			$data{$acl}{$proto}{$a} } keys
%{$data{$acl}{$proto}}) {
> 			
> 			# Do what you need

#######

> 			
> 		}
> 	}
> }
> 


You'll find that this is what i tried, but it is not being sorted
at all.  It appears that there is some overriding of the variables
within the sort routine, and it isn't getting the full values.

############### Attempt one ############
foreach $port (sort mostusedsvc keys %{$service{$acl}{$proto}}) {
			my($name,$aliases,$p,$t) =
getservbyport($port,$proto);
			print "Port: $port ($name) = " ,
$service{$acl}{$proto}{$port} , "\n";
}
sub mostusedsvc { $service{$acl}{$proto}{$b} <=> $service{$acl}{$proto}{$a}
}


:: This prints in seemingly random order.

############### Attempt two ############

@ports = sort { $service{$acl}{$proto}{$b} <=> $service{$acl}{$proto}{$b} }
		 keys %{$service{$acl}{$proto}};

foreach $port ( @ports ) {
	my($n,$a,$p,$t) = getservbyport($port,$proto);
	print "Port: $port ($n) = " , $service{$acl}{$proto}{$port} , "\n";
}

:: This also prints in seemingly random order


These are both functionally the same, and should each behave as one
expected,
but for some reason, neither work.

Where is the grammatical difference between my two versions, and your
versions,
that keep mine from working?  

=================================================
Mailing list info:  If at any time you wish to (un|re)subscribe to
the list send the request to majordomo at hfb.pm.org.  All requests
should be in the body, and look like such
                  subscribe anchorage-pm-list
                  unsubscribe anchorage-pm-list



More information about the Anchorage-pm mailing list