egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

multiple IF

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
m4st3r
Voice


Joined: 14 Sep 2006
Posts: 5

PostPosted: Mon Oct 09, 2006 9:04 pm    Post subject: multiple IF Reply with quote

Hello Wink

im working on a script, and i want to know if i can use list or something in IF cmd .. Example:
For the moment i use something like this:
Code:

if {[string match *test* $checkname] == 0 && [string match *roger* $checkname] == 0 && [string match *mary* $checkname] == 0 && [string match *merlin* $checkname] == 0 && [string match *polly* $checkname] == 0 && [string match *mandie* $checkname] == 0 } {

but i have ALOT of IF like this ... i want to know i i can use something like a "list" like:
Code:

list = "*test*,*roger*,*mary*, ..... "
if {$checkname match $list ) { ....


Thanks
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Mon Oct 09, 2006 10:11 pm    Post subject: Reply with quote

Yes.

Code:

set nicknames "name1 name2 name3 name4"

if {[lsearch -exact $nicknames $checkname] != -1} {
     # named matched
} else {
     # not matched
}

Or use lsearch -glob for matching wildcards

if {[lsearch -glob $nicknames *$checkname*] != -1} {
     # etc
}
Back to top
View user's profile Send private message
metroid
Owner


Joined: 16 Jun 2004
Posts: 771

PostPosted: Tue Oct 10, 2006 1:38 am    Post subject: Reply with quote

Also, since string match will only return 1 or 0, you can simply use

Code:
if {![string match *test* $checkname] && ![string match *roger* $checkname] && ![string match *mary* $checkname] && ![string match *merlin* $checkname] && ![string match *polly* $checkname] && ![string match *mandie* $checkname]} {
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Tue Oct 10, 2006 11:12 am    Post subject: Reply with quote

rosc2112 wrote:
Or use lsearch -glob for matching wildcards

His wildcards are in the list, not in the part matched against the list...
Something like this might do what he wants:
Code:
switch -glob -- $checkname {
   *test* -
   *roger* -
   *mary* -
   *merlin* -
   *polly* -
   *mandie* {
      # match
   }
   default {
      # no match
   }
}

_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber