我希望使用 # 符号,该符号表示后面的所有内容都将成为变量值中的注释。所以,我想写以下内容:
set Dev1_Number 1#
set Dev2_Number 2#
但是程序只将 1 和 2 识别为可以放置变量内存位置的值。有没有办法解决这个问题?
我希望使用 # 符号,该符号表示后面的所有内容都将成为变量值中的注释。所以,我想写以下内容:
set Dev1_Number 1#
set Dev2_Number 2#
但是程序只将 1 和 2 识别为可以放置变量内存位置的值。有没有办法解决这个问题?
Tcl comments only occur when the comment character is the first character of a command word (http://www.tcl.tk/man/tcl8.5/TclCmd/Tcl.htm#M29). You'll see code with end-of-line comments preceded by a semicolon
set foo bar ;# this is a comment
set foo bar # this is an error!
That's not the case in your example. In your example, the hash is merely data.
Your comments indicate your editor is making an incorrect assumptions about Tcl syntax. What editor are you using?
If you are concerned, you can "force" the hash to be part of the value by using quotes
set Dev1_Number "1#"
set Dev1_Number {1#}
使用反斜杠字符,它会转义该字符的原始含义。
set a 3\#
puts "a=$a"
output: a=3