I have a code.
If input parameter match opt,
then print opt-content
But result is not my expected: How do I solved it?
As following I describe:
I type:
$ tclsh t.tcl -B bb -O oo
I got:
bb
bb
oo
--------
Non
--------
oo
bb
oo
--------
Non
--------
Result seems to goes no match then print default message,
but argument seem to be read(substitute) correct.
FULL CODE
package require cmdline
set parameters {
{B.arg "" "Build Dir"}
{O.arg "" "Output Dir"}
}
array set arg [cmdline::getoptions argv ${parameters}]
set requiredParameters {B O }
foreach iter ${requiredParameters} {
if {$arg(${iter}) == ""} {
error "Missing required parameter: -${iter}"
} else {
puts $arg(${iter})
puts $arg(B)
puts $arg(O)
puts "--------"
switch $arg(${iter}) {
$arg(B) {
puts $arg(${iter})
}
$arg(O) {
puts $arg(${iter})
}
default {
puts "Non"
}
}
puts "--------"
}
}
Finally, I got the solution here
The braced switch seems to create a new namespace, which isolate outside variable.
Refer to here: