Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TCL variable naming / accession

Status
Not open for further replies.

atticuspf

Programmer
Apr 17, 2009
1
CH
Hi,

I have a loop which is setting variable names based on the index of the loop like this:

for { set j 1 } { $j <= 3 } { incr j } {
set A$j [ blah blah blah ]
}

this works fine. What I am trying to do now is re-access those variables in another loop later in my script for example:

for { set j 1 } { $j <= 3 } { incr j } {
set newvar [expr $A$j*10.0]
}

the point is that somehow I would like to access the variables $A1 $A2 and $A3 with using a construct like "$A$j".

All of my attempts: $A$j, $A($j), '$A$j' have failed miserably.

Does anyone have any suggestion?


 
Hi

Just to get A*'s value :
Code:
for { set j 1 } { $j <= 3 } { incr j } {
  set newvar [ set A$j ]
  puts $newvar
}
To also perform the calculation from your example :
Code:
for { set j 1 } { $j <= 3 } { incr j } {
  set newvar [ expr [ set A$j ]*10.0 ]
  puts $newvar
}


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top