Tcl's arrays cannot be nested (except in very old versions of Tcl, where there were bugs which let you do it). You can often use a composite key such as a,b,c
(or $a,$b,$c
) to achieve a similar effect, but that's really just leveraging the fact that keys are general strings and not numbers or simple words.
set A(123,$xyz) "the quick brown $fox"
set B($pqr,456) "the lazy dogs"
In addition to this, you can't really put references to variables in variables. You'd have to do some additional munging:
foreach {key value} [array get tmp1] {
set A($foo,$key) $value
}
Tcl 8.5's dictionaries (where the mapping is a value, not a variable collection) would indeed be a better solution for the things you're looking to do, particularly since 8.4 is now entirely end-of-lifed (and I know of some really nasty bugs in it that won't be fixed). I think there's a dict
package that implements a partial backport of the functionality for 8.4, but I'm not entirely sure about that as I didn't do the packaging and had already moved on to 8.5 at that point; it won't be maintained…
set A(foo,bar,baz) qux
– glenn jackmanset A($foo) [array get tmp]
– glenn jackmanupvar 0 arrayvar(key) refvar
;array set refvar {key value}
. It does not work: refvar does not exist yet, but is already blocked to not become an array. – MKaama