I have a question about list in tcl, what is the correct way to assign value to a list?
set employeeList ""
set TYPEID_3456 8
set TYPEID_9876 6
set TYPEID_6578 7
if {$employeeType=="1"} {
set employeeList "8"
} elseif {$employeeType=="2"} {
set employeeList "6 7"
} else {
prints "failed"
}
foreach employee $employeeList {
if {$employee==$TYPEID_3456} {
#do something
} elseif {$employee==$TYPEID_9876} {
#do something
} elseif {$employee==$TYPEID_6578} {
#do something
}
}
is this a correct way? because it tells me the TYPEID_3456 can not read.
What you wrote is correct: the string values will be interpreted as a list in the
foreachcommand.However I would write it like this to be clearer about your intentions, and use the
switchcommand to be more concise:Or, create a data structure that combines the
employeeListandemployeeType: