next up previous index
Next: Arrays Up: Procedures Previous: Variable Number of

Local and Global Variables

Tcl has local and global variables.   Variables which occur in a procedure and which are not explicitly declared as global are local to this procedure. Variables which occur outside of any procedure, or which are explicitly declared as global with the global   command, are global.

It is a frequent source of errors to omit the global   declaration in a procedure which has to share variables with other procedures. Also variables which occur in the Prolog predicate tcl/1,2,3   outside of any procedure are implicitly global.

The value of a variable can be obtained by prefixing it with the dollar sign (variable substitution). Alternatively, the set command also returns the value of a variable.



Micha Meier
Tue Jul 2 09:49:39 MET DST 1996