Here's a GRT variant on the ST approach above that will, for sufficiently large datasets, be faster because it relies on the default sort comparison:
c:\@Work\Perl\monks>perl -wMstrict -le "use Socket; ;; my %hosts = ( host0 => { ip => q{17.198.26.3} }, host1 => { ip => q{113.34.87.9} }, host2 => { ip => q{23.6.8.136} }, host3 => { ip => q{10.45.18.207} }, host4 => { ip => q{192.168.31.8} }, host5 => { ip => q{10.17.227.3} }, host6 => { ip => q{192.168.1.6} }, host7 => { ip => q{172.16.1.1} }, host8 => { ip => q{3.77.45.22} }, host9 => { ip => q{17.216.1.1} }, ); ;; my $aton = 'a4'; ;; print qq{$_ - $hosts{$_}->{ip}} for map unpack(qq{x[$aton] a*}), sort map pack(qq{$aton a*}, inet_aton($hosts{$_}->{ip}), $_), keys %hosts ; " host8 - 3.77.45.22 host5 - 10.17.227.3 host3 - 10.45.18.207 host0 - 17.198.26.3 host9 - 17.216.1.1 host2 - 23.6.8.136 host1 - 113.34.87.9 host7 - 172.16.1.1 host6 - 192.168.1.6 host4 - 192.168.31.8
Give a man a fish: <%-{-{-{-<
In reply to Re^2: Sorting Hash Value Object's IPv4 Address
by AnomalousMonk
in thread Sorting Hash Value Object's IPv4 Address
by razmeth
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |