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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.