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.

using list in a foreach command

Old posts that have not been replied to for several years.
S
Solarin
Voice
Posts: 29
Joined: Wed Apr 09, 2003 1:50 pm
Location: Sydney Australia
Contact:

Post by Solarin »

Hmmm... well you are correct on the break; command. I did not have that in there. Thanks for that. I had an oversight there. However it is still 8 rather than 7.

As for the nick problem, it definitely has to do with string matching on an element of $cv_bannednicks. What would you suggest from here?

Perhaps I should throw another nick in the list for test sake.
S
Solarin
Voice
Posts: 29
Joined: Wed Apr 09, 2003 1:50 pm
Location: Sydney Australia
Contact:

Post by Solarin »

Ok I did some testing and this is what I found with the following code:

Code: Select all

set cv_bannednicks {[xxx]
[fastshit]-}
...
  set nick "[lindex [split $args " "] 6]"
  set cv_host($nick) "[lindex [split $args " "] 8]"
  foreach s $cv_bannednicks {
   if {[string match -nocase *$s* $nick]} { 
    putlog "debug: would have banned *@$cv_host($nick) based on $s with $nick"
    break;
   }
  }
The output resulted with:
[01:34] (Botnickhere): [05:37] debug: would have banned *@censored.host.tmns.net.au based on [xxx] with mZ[SXCRXY]sad
[01:34] (Botnickhere): [05:37] debug: would have banned *@censored.host.gte.net based on [xxx] with cxhdxaes

I don't get it. Can anyone help here?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

haha, omg.... we are all stupid to not notice this one earlier! we should be doomed!
you must escape the [] braces, but not because TCL tries to execute them, but because string match uses it like regexp, [fastshit] matchs any string containing a single f OR a OR s OR t OR h OR i :D. Just the - at the end prevents matching a bit, because it must match with a following - ^.^.

http://www.tcl.tk/man/tcl8.4/TclCmd/string.htm#M35
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
awesomeawyeah
Voice
Posts: 4
Joined: Sun Jun 26, 2005 8:40 am
Location: irc.awyeah.org
Contact:

Post by awesomeawyeah »

You can also use lists in this format, which is more better:

Code: Select all

set mylist {
{my_element1}
{my_element2}
{my_element3}
}
S
Solarin
Voice
Posts: 29
Joined: Wed Apr 09, 2003 1:50 pm
Location: Sydney Australia
Contact:

Post by Solarin »

what's the advantage of doing it that way?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

For example:

Code: Select all

set list {
 "bl[a]"
 "fo\o"
}
foreach bar $list {
 putlog $bar
}
this will putlog:
bl[a]
foo
but

Code: Select all

set list {
 {bl[a]}
 {fo\o}
}
foreach bar $list {
 putlog $bar
}
will putlog
bl[a]
fo\o
to putlog fo\o using the first, you should use "fo\\o" instead of "fo\o".
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

It won't matter if it contains brackets then
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

MeTroiD wrote:It won't matter if it contains brackets then
exactly, unless you eval it :P
S
Solarin
Voice
Posts: 29
Joined: Wed Apr 09, 2003 1:50 pm
Location: Sydney Australia
Contact:

Post by Solarin »

Thanks for the help guys. :)
Locked