Here is a script that shows the problem:
#----------------------------
set x 1
set y1 "y1"
proc ok {} {
global x
global y$x
puts "$x [set y$x]"
}
proc fail {} {
global x y$x
puts "$x [set y$x]"
}
ok
fail
#----------------------------
Regards
E Wilson
all tokens of a line are evaluated ($ substitution [] substitution
{*} expansion _and then_ this list is run as a command (item1) with
arguments Item-2 .. Item-last.
Thus $x must resolve _before_ the command [global] sees any of this.
uwe
Ah, thanks for that clear explanation.
Evil son :-)
Do you understand why this is so? It's an important lesson to learn
about Tcl.
The explanation is pretty simple: tcl expands all variables before
calling the command. So, y$x is expanded, and _then_ passed to the
global command. At the point in time that y$x is expanded, x is undefined.