reisinge has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks, I have a data structure like this:
It's a HoH where nested keys are ports and values are number of connections to that port. I'm printing out the data like this:$VAR1 = { '1.2.3.4' => { '27029' => 5, '20617' => 1 + }, + '1.2.3.5' => { + '51509' => 1, + '17427' => 1, + '63961' => 7, + '22331' => 1, + '20780' => 7 + }, + '1.2.3.6' => { + '1500' => 3 + }, + };
I'd like to sort the output based on the number of connections to a port, ex.:for my $ip ( keys %conn ) { for my $port ( keys $conn{$ip} ) { if ( $conn{$ip}{$port} > $max_conns ) { printf "%-15s connected to TCP port %5d %9d times\n", $ip, + $port, $conn{$ip}{$port}; } } }
How do I write a sort like this? (You can find the whole script here.)1.2.3.5 connected to TCP port 20780 7 times 1.2.3.4 connected to TCP port 27029 5 times 1.2.3.6 connected to TCP port 1500 3 times ...
Well done is better than well said. -- Benjamin Franklin
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting a HoH by values of the nested hashes
by hdb (Monsignor) on Nov 20, 2013 at 12:42 UTC | |
|
Re: Sorting a HoH by values of the nested hashes
by Anonymous Monk on Nov 20, 2013 at 12:34 UTC | |
|
Re: Sorting a HoH by values of the nested hashes
by Laurent_R (Canon) on Nov 20, 2013 at 13:29 UTC | |
|
Re: Sorting a HoH by values of the nested hashes
by Random_Walk (Prior) on Nov 20, 2013 at 23:06 UTC |