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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Variable Substituion

Status
Not open for further replies.

cptk

Technical User
Mar 18, 2003
305
US
${var}is the same as $var, and
${var_array(x,y)} is the same as $var_array(x,y), but ...

for $var_array($x,y) neither
${var_array($x,y)} nor ${var_array(${x},y)} works. How come?
 
You don't need to protect the name of a variable if its name contains only alphanumerics and underscores.
The parenthesis () are not part of the name but indicates the index of the element in the array.
It is perfectly legal to write:
Code:
$array($element)
and, as expected, to get the value of the element whose index is the value of the
Code:
element
variable in the array
Code:
array
.

Enclosing the parenthesis inside braces has for effect to avoid any evaluation of the string inside the braces (the string is taken as is).

Code:
${array($element)}
is the value of the variable whose name is
Code:
array($element)
. This name contains parenthesis and dollar sign and is very dangerous to use ;-)

Hopefully you can code:
Code:
foreach element {one two threee four} { lappend res $aray($element) }
HTH

ulis

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top