How to print multiple arrays in TCL?
<pre><code>#!/usr/bin/expect -f

set myarr1(chicken) animal
set myarr1(cows) animal
set myarr1(tiger) animal
set myarr1(horse) animal

set myarr2(carrot) vegetable
set myarr2(tomato) vegetable
set myarr2(potato) vegetable
set myarr2(pea) vegetable

set arr_list { myarr1 myarr2 }

foreach key [array names [lindex $arr_list 0]] {
    puts "${key}=$[lindex $arr_list 0]($key)"
}

foreach key [array names [lindex $arr_list 1]] {
    puts "${key}=$[lindex $arr_list 1]($key)"
}
</code></pre>

<p>Output obtained:</p>

<pre><code>cows=$myarr1(cows)
horse=$myarr1(horse)
chicken=$myarr1(chicken)
tiger=$myarr1(tiger)
tomato=$myarr2(tomato)
pea=$myarr2(pea)
potato=$myarr2(potato)
carrot=$myarr2(carrot)
</code></pre>

<p>Required output:</p>

<pre><code>cows=animal
horse=animal
chicken=animal
tiger=animal
tomato=vegetable
pea=vegetable
potato=vegetable
carrot=vegetable
</code></pre>

<p>I am able to get the required output if I use the following in foreach loop:</p>

<pre><code>foreach key [array names myarr1] {
    puts "${key}=$myarr1($key)"
}

foreach key [array names myarr2] {
    puts "${key}=$myarr2($key)"
}
</code></pre>

<p>I am trying to create a list of array names and then loop through that list of array names and print it.  If there is a better way to approach this problem, I am all ears. Thanks for the assist !</p>