2011-04-04 52 views
0

说有这样的代码:如何打印一些操作的级联在TCL

set val "Hello" 
set listA {} 

lappend listA 6 7 

现在我想放以下内容:

puts "${val} user! Your list contains two values. First is [lindex $listA 0] and the second is [lindex $listA 1]" 

我怎么能这样做呢?

回答

1

好的,我找到了答案。问题在于,在我的实际代码中,我使用“[”和“]”符号作为字符串,但没有“\”。

所以我需要写:

puts "Zone No ${key} has Range\[ [lindex $value 0] - [lindex $value 1] \]" 

对不起,我的问题。

4

我不完全确定我是否理解正确。但是你做了什么应该工作,有一个小的修改:

set val "Hello" 
set listA {6 7} 
# or: 
# set listA {} 
# lappend listA 6 7 
puts "${val} user! Your list contains two values. First is [lindex $listA 0] and the second is [lindex $listA 1]" 

给人的输出:

Hello user! Your list contains two values. First is 6 and the second is 7 
+0

你说得对,谢谢您考虑我的问题! – Narek 2011-04-04 15:07:52