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) }
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.