作为脚本语言tcl的"[]"使用尤为重要
经典报错之variable references require preced
错误的情况:
% if {!string compare $x hell} {
puts "string is hell"
正确的情况:
% set x hello
% if {![string compare $x hell]} {
puts "string is hell"
} elseif ![string compare $x hell] {
puts "string is hel"
} elseif ![string compare $x hello] {
puts "string is hello"
} else {puts "error input string"}
> string is hello
-
错误原因:发生替换时必须有[] 将其括起来,否则语法错误
-
总结:有替换[]必须伴随
代码参考 :tcl编程初步