switch-statement - Tcl开关盒错误,我需要对错误进行适当的解释

标签 switch-statement syntax-error tcl

请帮助我检测以下代码中的错误

proc strcmp { d1 d2 } {
    set res [string compare $d1 $d2]

    switch $res  
    0 {
    puts "String is equal "
    } 
    1 {
    puts "$d1 > $d2"
    } default { 
    puts "$d2 > $d1"
    }

}

当我尝试在tcl 8.5中执行时收到此错误消息

错误的#args:应该是“switch?switchs?字符串模式主体……?默认主体?”

最佳答案

您在另一行上有“0”。 Tcl将换行符视为命令终止符。您可能会看到类似“0:无此命令”的错误

使用任一行连续

switch $res  \
0 {
    puts "String is equal "
} \
1 {
    puts "$d1 > $d2"
} \
default { 
    puts "$d2 > $d1"
}

或封闭支架(便于阅读)
switch $res  {
    0 {
        puts "String is equal "
    } 
    1 {
        puts "$d1 > $d2"
    } 
    default { 
        puts "$d2 > $d1"
    }
}

文件:
  • http://tcl.tk/man/tcl8.6/TclCmd/Tcl.htm(规则1和9)
  • http://tcl.tk/man/tcl8.6/TclCmd/switch.htm
  • 关于switch-statement - Tcl开关盒错误,我需要对错误进行适当的解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27765748/

    相关文章:

    c - NULL 检查多个文件指针的最佳/最快方法?

    C - 具有多个案例编号的开关

    ruby - 为什么使用 return 语句的带有双符号的 Ruby 表达式会导致语法错误

    shell - 执行tclsh时需要什么shell

    tcl - Tcl eval 命令是否阻止字节编码?

    java - 带有构造函数的枚举并在 switch JAVA 中使用它

    C#8.0 switch 语句和局部变量

    python - 如何将python语法错误重定向到MFC或其他GUI框架中的文本框?

    c# - 使用ObjectQuery <T>进行过滤错误

    python - 在Windows上为python编译线程安全的tcl