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
In reply to Sorting a HoH by values of the nested hashes by reisinge
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |