博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Tcl/Tk的Switch模块中慎用注释
阅读量:2347 次
发布时间:2019-05-10

本文共 1686 字,大约阅读时间需要 5 分钟。

今天改了一段Tcl代码,一段非常复杂的非常长的swith代码,总是遇到这样一个奇怪的错误:

"extra switch pattern with no body, this may be due to a comment incorrectly placed outside of a switch body - see the "switch" documentation"
于是我检查{}是否匹配,检查entry写的是否正确,检查switch的变量是否正确……反复几遍之后,错误仍然在,几近崩溃。
Google了半天,也没找到解决方法。
最终还是抱着试试看的心态打开了Tcl/Tk经典书《Practical Programming in Tcl and Tk》,打开第六章第二节,发现本节结束处赫然写着这样一段话:
A comment can occur only where the Tcl parser expects a command to begin. This restricts the location of comments in a switch command.  You must put them inside the command body associated with a pattern, as shown in . If you put a comment at the same level as  the patterns, the switch command will try to interpret the comment as one or more pattern-body pairs.
该示例如下:
Example 6-6 Comments in switch commandsswitch -- $value {   # this comment confuses switch   pattern { # this comment is ok }}
我赶紧查看了一下我的代码,发现有好几个处“} ;#end of XXX”这样的注释。把它们去掉之后,就可以正常work了。
下面就是带有错误注释的不能工作的代码段。
append C(HostMMCAP) ",$ap"                                                # Record this reservd AP                                                append MMCAPRSVD " $ap"				        } ;# end of if                                } else {                                        AlertBox warn /"You can NOT reserve it! This AP has been reserved by $rsv_login in $rsv_site with COOL session (COOLID) $rsv_id.Please contact user /"$rsv_login/" if you really want to use it."                                        set MMCAPDISPLAY($ap) 0                                        return                                } ;# end of else                        } ;# end of entry "reserved"
由此得知,虽然“;#”这样的注释在Tcl中一般是很常见的,但是在switch中语句中是不能用的,只能在单独一行里写注释。
以此文为记。

 

转载地址:http://hnpvb.baihongyu.com/

你可能感兴趣的文章
RMAN参考使用手册(转)
查看>>
解决WEB ADI打开EXCEL文档时一直停留在"Your document is being created"界面的问题
查看>>
为什么删除文件后磁盘空间还是不变
查看>>
VNC server简单配置vnc
查看>>
win7 安装的offic2007
查看>>
rman本库恢复性测试
查看>>
IBM TSM磁带管理操作小记一则
查看>>
ORA-00258: NOARCHIVELOG 模式下的人工存档必须标识日志
查看>>
Java调用bat文件
查看>>
此责任无可用函数
查看>>
java获取数字和汉字
查看>>
excel Option Explicit webadi
查看>>
ICX错误
查看>>
windows Xp NTLDR is missing
查看>>
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
查看>>
Centos 6.x 安装配置MySQL
查看>>
-source 1.5 中不支持 diamond 运算 请使用 -source 7 或更高版本以启用
查看>>
jar包读取资源文件报错:找不到资源文件(No such file or directory)
查看>>
超简单:Linux安装rar/unrar工具与解压到目录示例
查看>>
Eclipse创建Maven Java8 Web项目,并直接部署Tomcat
查看>>