【问题标题】:Using $variable in Parenthesis in Tcl (proc)在 Tcl (proc) 的括号中使用 $variable
【发布时间】:2015-06-12 09:15:15
【问题描述】:

我在 tcl 中的部分代码是:

proc Frame {columnLine} {
.
.
.
}

现在我想在括号中使用 $variable。例如:

set x 2.
set columnLine {$x 5. 10. 15.}

但是,在运行 Tcl 之后,我遇到了一个错误!我该如何解决这个问题?

【问题讨论】:

    标签: tcl


    【解决方案1】:

    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.}]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-10
      • 1970-01-01
      相关资源
      最近更新 更多