如何将变量输入到 Tcl 开关代码块中?
How can I input variables into the Tcl switch code block?
我正在尝试在 Tcl 8.5 中做一些非常简单的事情。
我有一个变量和另一个变量,我试图在一个开关中将它们等同起来。在 Python & Ruby 中很容易完成的事情,我无法在 Tcl 中工作。手册页 http://www.tcl.tk/man/tcl8.5/TclCmd/switch.htm 没有帮助。
查看代码和结果:
set k 4
switch 4 {
$k { puts "yey" }
default {puts "no recon" }
}
exit
它输出:
no recon
有什么想法吗?
Tcl 不会在大括号内进行替换。用双引号将代码更改为
set k 4
switch 4 "
$k { puts yey }
default {puts \"no recon\" }
"
或者单行写成
switch 4 $k { puts yey } default {puts "no recon" }
我正在尝试在 Tcl 8.5 中做一些非常简单的事情。 我有一个变量和另一个变量,我试图在一个开关中将它们等同起来。在 Python & Ruby 中很容易完成的事情,我无法在 Tcl 中工作。手册页 http://www.tcl.tk/man/tcl8.5/TclCmd/switch.htm 没有帮助。 查看代码和结果:
set k 4
switch 4 {
$k { puts "yey" }
default {puts "no recon" }
}
exit
它输出:
no recon
有什么想法吗?
Tcl 不会在大括号内进行替换。用双引号将代码更改为
set k 4
switch 4 "
$k { puts yey }
default {puts \"no recon\" }
"
或者单行写成
switch 4 $k { puts yey } default {puts "no recon" }