Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm having trouble with this problem sorting the IP address in increasing numeric order. If the first octet is the same, sort by the second octet, if the second octet is the same sort by the third octet, etc. IP addresses have a different number of digits between the periods so you will have to split the data up.
An example is:
127.0.0.1
10.129.30.5
10.129.30.2
255.255.255.255
10.109.30.5
142.222.130.23
10.109.1.1
142.222.87.30
I can sort it by increasing to decreasing number but not by each octet.
The answer should be:
10.109.1.1
10.129.30.2
10.129.30.5
10.109.30.5
127.0.0.1
142.222.87.30
142.222.130.23
255.255.255.255
by Thank You
An example is:
127.0.0.1
10.129.30.5
10.129.30.2
255.255.255.255
10.109.30.5
142.222.130.23
10.109.1.1
142.222.87.30
I can sort it by increasing to decreasing number but not by each octet.
The answer should be:
10.109.1.1
10.129.30.2
10.129.30.5
10.109.30.5
127.0.0.1
142.222.87.30
142.222.130.23
255.255.255.255
by Thank You
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: sorting ip octets
by Tanktalus (Canon) on Feb 16, 2005 at 18:59 UTC | |
by Anonymous Monk on Feb 16, 2005 at 19:04 UTC | |
by Tanktalus (Canon) on Feb 16, 2005 at 19:08 UTC | |
by Anonymous Monk on Feb 16, 2005 at 19:10 UTC | |
Re: sorting ip octets
by demerphq (Chancellor) on Feb 16, 2005 at 18:54 UTC | |
by Anonymous Monk on Feb 16, 2005 at 18:59 UTC | |
by demerphq (Chancellor) on Feb 16, 2005 at 19:09 UTC | |
Re: sorting ip octets
by eclark (Scribe) on Feb 16, 2005 at 21:29 UTC | |
by eclark (Scribe) on Feb 16, 2005 at 21:34 UTC | |
by Animator (Hermit) on Feb 17, 2005 at 10:15 UTC | |
Re: sorting ip octets
by Animator (Hermit) on Feb 16, 2005 at 20:14 UTC | |
Re: sorting ip octets
by TedPride (Priest) on Feb 16, 2005 at 19:13 UTC |
Back to
Seekers of Perl Wisdom