| View previous topic :: View next topic |
| Author |
Message |
m4st3r Voice
Joined: 14 Sep 2006 Posts: 5
|
Posted: Mon Oct 09, 2006 9:04 pm Post subject: multiple IF |
|
|
Hello
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 |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Mon Oct 09, 2006 10:11 pm Post subject: |
|
|
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 |
|
 |
metroid Owner
Joined: 16 Jun 2004 Posts: 771
|
Posted: Tue Oct 10, 2006 1:38 am Post subject: |
|
|
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 |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Tue Oct 10, 2006 11:12 am Post subject: |
|
|
| 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 |
|
 |
|