On Aug 9, Jeremy Kister said:
my @s = map $_->[ 1 ],
sort { $a->[ 0 ] cmp $b->[ 0 ] }
map [ inet_aton( $_->{ N } ), $_ ],
@a;
Now to analyze WTF we're doing here :)
Paul's answer had a slight typo in it -- he was comparing $a->[0],
$a->[1], $a->[2], and $a->[3], when he should have been comparing $a->[1],
$a->[2], $a->[3], and $a->[4].
As for John's answer, it does the same thing as Paul's would have. It
just bundles the logic by using the Socket module's inet_aton() function.
inet_aton() takes an IP address or hostname and returns a four-byte string
representing the address. Each byte represents a number from 0 to 255,
stored as an ASCII character. The IP address 65.66.67.68 would be stored
as "ABCD".
It then compares the four-byte strings, using simple string comparison,
since 'cmp' uses the ASCII values of the characters in the string to
determine if a string is "less than" another.
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>