http://qs321.pair.com?node_id=970881


in reply to Sorting Hash / Array

Not sure which part you are puzzling over. Simplistically:
use strict; use warnings; my $VAR1; $VAR1 = { '127' => { 'network' => '10.182.48.0/24', 'VLAN' => '3509' }, '32' => { 'network' => '10.182.12.0/25', 'VLAN' => '2121' }, '90' => { 'network' => '10.183.243.128/25', 'VLAN' => '3494' } }; sub custom { # $a and $b are keys my $anet = $VAR1->{$a}{network}; my $bnet = $VAR1->{$b}{network}; return $anet cmp $bnet; } my @result = sort custom keys %$VAR1;
However it would probably be better to use Net::IPAddress to convert the IP address to a 32-bit int, then use <=> to compare them, and compare the ports if the addresses are the same.