【发布时间】:2015-06-12 09:15:15
【问题描述】:
我在 tcl 中的部分代码是:
proc Frame {columnLine} {
.
.
.
}
现在我想在括号中使用 $variable。例如:
set x 2.
set columnLine {$x 5. 10. 15.}
但是,在运行 Tcl 之后,我遇到了一个错误!我该如何解决这个问题?
【问题讨论】:
标签: tcl
我在 tcl 中的部分代码是:
proc Frame {columnLine} {
.
.
.
}
现在我想在括号中使用 $variable。例如:
set x 2.
set columnLine {$x 5. 10. 15.}
但是,在运行 Tcl 之后,我遇到了一个错误!我该如何解决这个问题?
【问题讨论】:
标签: tcl
Tcl 不对{braces} 内的内容进行替换。如果你想要替换,你必须或者将整个单词放在"double quotes" 中,或者使用subst 命令:
set x 2.
set columnLine [subst {$x 5. 10. 15.}]
set x 2.
set columnLine "$x 5. 10. 15."
使用subst 的一个优点是您可以选择只替换变量并留下反斜杠和[bracketed 命令调用]。这有时确实非常有用。
set x 2.
set columnLine [subst -nobackslashes -nocommands {$x 5. 10. 15.}]
【讨论】: