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.
Old posts that have not been replied to for several years.
LorT
Voice
Posts: 15 Joined: Sun Mar 09, 2003 6:11 pm
Post
by LorT » Thu Mar 11, 2004 12:41 pm
i have 11 conditions in a proc.
if {[lindex $text 0] == "commands"} {
pub:learn:add $nick $chan[lrange $text 0 end]
return 0
}
if {[lindex $text 0] == "rosters"} {
pub:learn:add $nick $chan[lrange $text 0 end]
return 0
}
to......
if {[lindex $text 0] == "servers"} {
pub:learn:add $nick $chan[lrange $text 0 end]
return 0
}
puthelp "notice $nick :invalid option. optin: ............"
new i change it to
if {[lindex $text 0] == "commands" || [lindex $text 0] == "rosters" ......|| [lindex $text 0] == "servers"} {
pub:learn:add $nick $chan[lrange $text 0 end]
return 0
}
puthelp "notice $nick :invalid option. optin: ............"
have a better way to do if?
edit: change the string name
Last edited by
LorT on Thu Mar 11, 2004 1:45 pm, edited 1 time in total.
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Thu Mar 11, 2004 12:55 pm
Code: Select all
if {[string match {[a-k]} [lindex $text 0]]} {
whatever
}
Have you ever read "The Manual"?
LorT
Voice
Posts: 15 Joined: Sun Mar 09, 2003 6:11 pm
Post
by LorT » Thu Mar 11, 2004 1:39 pm
sorry my bad
the string arent a-k is only ej.
the string are commands, roster, rules, records, servers....
how can i check if?
Xpert
Halfop
Posts: 88 Joined: Mon Mar 08, 2004 7:03 am
Post
by Xpert » Thu Mar 11, 2004 1:52 pm
Code: Select all
if {([lindex $text 0] == "commands") || ([lindex $text 0] == "rosters") || ([lindex $text 0] == "rules") || ([lindex $text 0] == "servers")} {
pub:learn:add $nick $chan[lrange $text 0 end]
return 0
}
Don't forget the "(,)" if you have more than one condition
Xpert.
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Thu Mar 11, 2004 2:04 pm
Xpert : foo is not equal with FOO, FoO, fOO, etc. So, either use "string tolower" to lower the stuff you compare or use "string equal -nocase" Consult the
manual about them.
Once the game is over, the king and the pawn go back in the same box.
Xpert
Halfop
Posts: 88 Joined: Mon Mar 08, 2004 7:03 am
Post
by Xpert » Thu Mar 11, 2004 2:08 pm
Sorry, i forgot about the strlwr
Xpert.
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Thu Mar 11, 2004 2:11 pm
When you are using "strlwr" you are actualy calling an proc from alltools.tcl that will do that "string tolower" thing and this will slow your proc down a bit
Once the game is over, the king and the pawn go back in the same box.
strikelight
Owner
Posts: 708 Joined: Mon Oct 07, 2002 10:39 am
Contact:
Post
by strikelight » Thu Mar 11, 2004 2:24 pm
Alternatively....
Code: Select all
if {[regexp -nocase -- {^commands$|^rosters$|^rules$|^servers$} [lindex $text 0]]} {
... do stuff ...
}
However, while the code is more concise, regexp is a bit of a cpu eater, so it may be a few microseconds slower than using direct comparitive expressions.
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Thu Mar 11, 2004 5:05 pm
Code: Select all
% proc test find {
foreach way {
{set ok [expr {[lsearch -exact {word1 word2 word3 word4} $find]>-1}]}
{switch -- $find {word1 - word2 - word3 - word4 {set ok 1} default {set ok 0}}}
{set ok [expr {$find=="word1"||$find=="word2"||$find=="word3"||$find=="word4"}]}
{set ok [regexp {^(word1|word2|word3|word4)$} $find]}
} {
puts "[time $way 10000] (result: [eval $way])"
}
}
% test word1
4 microseconds per iteration (result: 1)
6 microseconds per iteration (result: 1)
7 microseconds per iteration (result: 1)
30 microseconds per iteration (result: 1)
% test word4
4 microseconds per iteration (result: 1)
6 microseconds per iteration (result: 1)
17 microseconds per iteration (result: 1)
30 microseconds per iteration (result: 1)
% test word12
4 microseconds per iteration (result: 0)
6 microseconds per iteration (result: 0)
17 microseconds per iteration (result: 0)
28 microseconds per iteration (result: 0)
Have you ever read "The Manual"?