Author Topic: How do I sort this sort of table...  (Read 1402 times)

0 Members and 1 Guest are viewing this topic.

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
How do I sort this sort of table...
« on: 10 December, 2003, 22:44:26 »
Accociative I think... (can't spell)

How do I sort it...


Code: [Select]
for vRANGE,vNET in Table do
local _,_,RANGE1,RANGE2 = strfind(vRANGE, "(%S+)-(%S+)")
curUser:sendmessage(BOTNAME," Range: "..RANGE1.." - "..RANGE2.."\t\tNetwork: "..vNET)
end

plz help me...

/NL
//NL

PtokaX forum

How do I sort this sort of table...
« on: 10 December, 2003, 22:44:26 »

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #1 on: 10 December, 2003, 23:52:55 »
not 2 sure but this might work.
Code: [Select]
local temp = {}
for vRANGE,vNET in Table do
   tinsert(temp, vRANGE)
end
sort(temp)
for i=1,getn(temp) do
local _,_,RANGE1,RANGE2 = strfind(temp[i], "(%S+)-(%S+)")
curUser:sendmessage(BOTNAME," Range: "..RANGE1.." - "..RANGE2.."\t\tNetwork: "..Table[temp[i]])
end

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline c h i l l a

  • Lord
  • ***
  • Posts: 347
  • Karma: +1/-0
(No subject)
« Reply #2 on: 11 December, 2003, 00:24:51 »
nightlitch... it depends if you have IP s to sort then you will need to use the sort func of the logger.
if you sort it with LUA sort function...  tings could get mixed up  like  230.0.0.0  above 32.0.0.0  but if you sort it by name then plops idea is the one, in any case you will need to first creat a non associative table  like plop did.

tinsert(temp,value)

the sort func of the logger,  computes the IP and compares it with the next one

ends up something like this

sort(table, function(a,b) return(Compute(a) < Compute(b)) end)

you need the the compute function.
« Last Edit: 11 December, 2003, 00:26:45 by c h i l l a »

PtokaX forum

(No subject)
« Reply #2 on: 11 December, 2003, 00:24:51 »