| |||||||||||
Using an array value as another array name Posted by shubb (shubb), 6 January 2006 Hi, I'm trying to use the values from one array as names of other arrays for excecuting commands.I create several data arrays with values. set testArr1('name') "test1" set testArr1('val1') "value11" etc... set testArr2('name') "test2" set testArr2('val1') "value21" etc... Then I create another array with the names of each data array. set arrayNames(0) "testArr1" set arrayNames(1) "testArr2" etc... I want to use the arrayNames in a foreach loop to get the name of each of the data arrays, so I can use the data in those arrays for commands. The problem is that when I use the foreach loop, it reads the names correctly, but it doesnt use the value to look up the data array by the same name. foreach arrData [array names arrayNames] { send_user "data array's name is $arrayNames($arrData)('name')\n" } What this returns is: data array's name is testArr1('name') data array's name is testArr2('name') when what I want to get is the value of testArr1('name'), which is "test1" and "test2" Any Idea how I to do this? As you can probably guess, I'm a beginner with Expect. Is there a better way to accomplish this? Thanks for any help you can offer. Posted by admin (Graham Ellis), 7 January 2006 I would tackle it rather differently - the way you try to store one name in another is a bit obtuse and you'll do better with just one array:Code:
runs Code:
Posted by shubb (shubb), 8 January 2006 Awesome! That works perfect.Thanks! I knew there had to be a better way to do that. This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |