I am a new user of tcl. I am having some trouble with arrays.
The following is a test program:
global a
proc parray {} {
set a(0) 11
set a(1) 22
}
parray
After I ran the procedure parray, I tried to access a(0) and a(1)
by typing:
set a(0)
I got an error message of "can't read "a(0)": no such variable
I also tried to declare the array a in the following form:
global a()
It did not work either.
Could someone help me how can I declare a global array and be able
to access it at any part of the program?
Thanks in advance.
Lili Kan
It needs to be declared global in each procedure.
--
Michael Salmon
#include <standard.disclaimer>
#include <witty.saying>
#include <fancy.pseudo.graphics>
Ericsson Telecom AB
Stockholm
To access a global variable inside a procedure you need to declare it global
inside the procedure like this:
proc foo {} {
global someVar
[...]
}
To *modify* a global variable inside a procedure you need to use the upvar
command:
proc foo {} {
upvar someVar x
set x someValue
[...]
}
Check the man page for details.
Cheers,
Dominik
-----------------------------------------------------------------------------
Dominik Zimmermann Technische Universitaet Berlin
Sekr. 5-6
email: dom...@cs.tu-berlin.de Franklinstr. 28/29
ph: +49-30-314-21762 10587 Berlin
Germany
Some people believe that the stars determine their fate;
I believe in the One who made the stars.