in reply to Re: Sorting Hash Value Object's IPv4 Address
in thread Sorting Hash Value Object's IPv4 Address

Good solution , and this is what I was too lazy to code, in my earlier post.

However, shouldn't the sort use the spaceship operator (<=>) rather than cmp, since the items being compared are numeric ?

        "I can cast out either one of your demons, but not both of them." -- the XORcist

  • Comment on Re^2: Sorting Hash Value Object's IPv4 Address

Replies are listed 'Best First'.
Re^3: Sorting Hash Value Object's IPv4 Address
by johngg (Canon) on Jan 30, 2016 at 12:38 UTC

    That's what I initially assumed when I started coding this but you get a shed load of

    Argument "^CM-^V" isn't numeric in numeric comparison (<=>) at ...

    warnings when you use <=>. That's because inet_aton() is actually returning a packed string. Consider the following:-

    johngg@shiraz:~/perl/Monks > perl -MSocket -E ' > say ord for split m{}, inet_aton( q{192.168.45.92} );' 192 168 45 92 johngg@shiraz:~/perl/Monks > perl -E ' > say ord for split m{}, pack q{C4}, split m{\.}, q{192.168.45.92};' 192 168 45 92 johngg@shiraz:~/perl/Monks >

    Therefore the cmp comparison is more appropriate.

    Cheers,

    JohnGG

      Thanks for the enlightenment (++). I learned something today (always good).

              "I can cast out either one of your demons, but not both of them." -- the XORcist