Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by NetWallah (Canon)
on Jan 30, 2016 at 00:47 UTC ( [id://1154052]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1154052]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-23 07:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found