Let's say I have a regular variable that contains the name of an existing array.
array set myarr {
key_1 val_2
key_2 val_2
}
set myvar myarr
I can found nowhere how I can iterate over myarr from myvar!
The variable myvar is a simple variable that is holding the name of another variable. You can use a read from it (with $ or set) anywhere where you'd expect to use the name of the variable:
foreach {key value} [array get $myvar] {
puts "$key => $value"
}
What you can't do directly is use the name to access the contents of the array. To do that, you'd usually use upvar 0 to map the named thing to something that you can work with more easily:
upvar 0 $myvar v
foreach key [lsort [array names v]] {
puts "$key => $v($key)"
}
(In this case, and provided you're using Tcl 8.6, you could use the -stride option to lsort to work with array get instead of array names, which would let you avoid making the alias. But that's a different way to achieve the same output really, and only applies if you're doing key-sorted array iteration…)
$myvarwhere you would otherwise writemyarr. Such as inarray names $myvar.