上午初学的Tcl/Tk访问数组结果的过程,在过程使用TCL
下面访问阵列面临的问题是我的问题发言
proc myproc {args} {
set aaa ""
set bbb ""
set ccc ""
foreach "field value" $args {
set $field $value
}
# assigning input args values to an array a
set a(3:0) $aaa
set a(6:4) $bbb
set a(25:7) $ccc
#do some computation on input arguments may be addition
#
#
#
# now the result am trying to fetch into another array b
set $b(word0) $x
set $b(word1) $y
set $b(word2) $z
set $b(word3) $u
return [array get b]
}
现在我需要传递参数给MYPROC和回报我需要访问数组。
set args_1 "g 1 h 4 k 6"
我尝试下面的语法,它被扔我的错误。
array set a [myproc[array get $args_1]]
有人可以帮我解决这个问题
试图给字符串作为输入的过程myproc
后来试图做一些计算与输入值。
以后所有计算得到了设置字符串值,被分配到数组如下
set $b(word0) $x
set $b(word1) $y
set $b(word2) $z
set $b(word3) $u
后要发这个数组b
作为回报。
例如:
proc myproc {} {
set $b(word0) $x
set $b(word1) $y
set $b(word2) $z
set $b(word3) $u
return [array get b]
}
我曾经试图访问数组b如下
array set a [myproc[array get b]]
它的工作:)能在调用函数来创造新的数组。
但是,需要传递的字符串参数MYPROC并获得回报阵列
请通过[教程](http://www.tcl.tk/man/tcl8.5/tutorial/自己的工作tcltutorial.html)至少在着手编写真正的代码之前。 – kostix