Sort IP List

Mike Bonner bonnmike at gmail.com
Fri Jun 29 11:37:12 EDT 2018


I don't know what speed differences there might be, but another option is
something like this..

function ipfunc pIp
   set the itemdel to "."
   set the numberformat to "###" -- force length of each chunk to 3

-- append the numbers together sans "." with padded 0's using numberformat
   repeat for each item tItem in pIp
         put tItem +0 after tIp -- do the add to force the numberformat to
work
   end repeat
   return tIp
end ipfunc

And then use it like so..
sort lines of myIpList ascending numeric by ipfunc(each)


On Fri, Jun 29, 2018 at 9:14 AM Bob Sneidar via use-livecode <
use-livecode at lists.runrev.com> wrote:

> Hi all.
>
> I somehow got on to how to sort IP addresses, seeing they are not real
> numbers, and read in the dictionary that the sort command is a "stable
> sort". This occured to me:
>
> function sortIPList pIPList
>    set the itemdelimiter to "."
>    sort lines of pIPList numeric by item 4 of each
>    sort lines of pIPList numeric by item 3 of each
>    sort lines of pIPList numeric by item 2 of each
>    sort lines of pIPList numeric by item 1 of each
>    return pIPList
> end sortIPList
>
> Enjoy!
>
> Bob S
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list