Sample Header Ad - 728x90

Iterating arrays in TCL where array names have a numeric suffix

0 votes
2 answers
241 views
In TCL, I have a few arrays whose names have a numeric suffix (i.e., whose names end with a number), like below:
array set ps0 [ list 0 15.885 1 55.43 1 0.254 2 0.227 3 0.177 ]
array set ps1 [ list 0  6.585 1 56.43 1 0.254 2 0.227 3 0.177 ] 
array set ps2 [ list 0 32.485 1 43.13 1 0.254 2 0.227 3 0.177 ]
I need to iterate over these in TCL and get the values, but, no matter what I do to escape the numeric suffix, I cannot get both the array and the contents.  Everything I've tried, such as:
ps$i($i)
"ps$i($i)"
or even using a set like:
set p ps$i
...does not work to get the array with the number index.  I get the error:
Original error: can't read "ps": no such variable
...for all possible combinations.  How can I do this (in TCL)?
Asked by poppycock (3 rep)
Feb 16, 2024, 04:06 AM
Last activity: Feb 16, 2024, 01:58 PM