我有以下一段 TCL 代码:
#wrong format:
set in_val "12 0 2 0 0 0 1 0 3 698"
#correct format:
#set in_val "12 0 1 0 0 0 1 0 3 698"
set val_ok [regexp {(\d+)\s([01]\s)([01]\s)([01]\s)([01]\s)([01]\s)([01]\s)([01]\s)(\d+)\s(\d+).*} $in_val Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11]
if {$val_ok==1} {
# correct format
puts "Correct format, continuing..."
puts "$Var2 $Var3 $Var4 $Var5 $Var6 $Var7 $Var8 $Var9 $Var10 $Var11"
} else {
# wrong format
puts "Wrong format, stimulus [$in_val]"
}
我想检查用 regexp 函数描述的格式是否正确。当 in_val var 具有正确的格式时,一切都很好,if 块被执行。但是,当格式错误时,我没有输入 else 块,而是收到以下错误:
invalid command name "12 0 2 0 0 0 1 0 3 698"
while executing
"$in_val"
invoked from within
"if {$val_ok==1} {
# correct format
puts "Correct format, continuing..."
puts "$Var2 $Var3 $Var4 $Var5 $Var6 $Var7 $Var8 $Var9 $Var10 $Var11"
} else {..."
(file "xxx.tcl" line 3)
我正在为 Windows 使用 ActiveState ActiveTcl 8.5.11.1。关于当 val_ok=0 并且正则表达式不匹配时为什么会出现错误的任何想法?谢谢!
JB