This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

question about foreach/string match

Old posts that have not been replied to for several years.
Locked
User avatar
sKy
Op
Posts: 194
Joined: Thu Apr 14, 2005 5:58 pm
Location: Germany

question about foreach/string match

Post by sKy »

Is there a way to do the same like this script but with more speed?
(hostlist is much bigger)

Code: Select all

set hostlist {
	"*.il24.net"
	"*.comcast.net"
	"*.jazztel.es"
	"*.telia.com"
	"*.attbi.com"
...........
...........
...........
}
bind join - * onjoin:check
proc onjoin:check { nickname hostname handle channel } {
 set host [lindex [split $hostname "@"] 1]
 foreach h $hostlist {
  if { [string match -nocase $h $host] } {
   procname $var $var ....
   return
  }
 }
}
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

if you bind join - "* <mask>" it might make it faster, but then you'll have alot of bind joins, so I suggest you keep it this way.
User avatar
sKy
Op
Posts: 194
Joined: Thu Apr 14, 2005 5:58 pm
Location: Germany

Post by sKy »

what about lsearch? i tryed but i can`t find "right match"
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

With lsearch you search for an element in a list and it will return it's position in the list (which would be a number) or -1 if it doesn't exist. So, you can't match with lsearch.
User avatar
sKy
Op
Posts: 194
Joined: Thu Apr 14, 2005 5:58 pm
Location: Germany

Post by sKy »

mmh :/
no other way?

how is the internal bot banlist coded? that`s still fast until the banlist is huge.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

dont disapoint the guy. of course lsearch can search for wildcards:
http://www.tcl.tk/man/tcl8.4/TclCmd/lsearch.htm#M10

you can probably speed up the thing, when you set the list like:
set hostlist {*.il24.net *.comcast.net *.jazztel.es *.telia.com *.attbi.com ...}

an alternitve would be to do:
set hostlist [lrange $hostlist 0 end]

this should strip any redudant code.

Code: Select all

#De_Kus# set hostlist
Currently:    "*.il24.net"   "*.comcast.net"   "*.jazztel.es"   "*.telia.com"   "*.attbi.com"
tcl: evaluate (.tcl): lrange $hostlist 0 end
Tcl: *.il24.net *.comcast.net *.jazztel.es *.telia.com *.attbi.com
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

hm.. maybe sort the list and use lsearch -sorted. i think that would be the most effective improvement.
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Tcl's lsearch won't work with -glob and -sorted at the same time. However you could write a search function that does that... it's kind of tricky because you have to split the list up based on where the wildcards are (beginning, middle, end). I was doing something like this for eggdrop 1.9.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

we still don't know how much the lrange and lsearch speed up does ^-^.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

If we use -glob with lsearch we can match an element with wildcards to an element in a list. So we can't match this!that@those to this!*@* in the list but we can do vice-versa.

example:
.tcl set thislist {"yo!*@*" "hayda*!me@*"}

.tcl lsearch -glob $thislist yo!hayda@haydek
Tcl: -1

.tcl lsearch -glob $thislist *!me@*
Tcl: 1
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Sky, how big is your list anyway? Unless it's really big I doubt this is much of an issue, but if it is, I'll try writing that thing I was talking about in tcl. Still might not make a whole lot of difference but it would be kind of fun.
User avatar
sKy
Op
Posts: 194
Joined: Thu Apr 14, 2005 5:58 pm
Location: Germany

Post by sKy »

It`s not too big and to slow now but the size will be bigger every day.
Locked