| 1 |
'\" |
| 2 |
'\" Copyright (c) 1993 The Regents of the University of California. |
| 3 |
'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. |
| 4 |
'\" |
| 5 |
'\" See the file "license.terms" for information on usage and redistribution |
| 6 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 7 |
'\" |
| 8 |
.TH global n "" Tcl "Tcl Built-In Commands" |
| 9 |
.so man.macros |
| 10 |
.BS |
| 11 |
'\" Note: do not modify the .SH NAME line immediately below! |
| 12 |
.SH NAME |
| 13 |
global \- Access global variables |
| 14 |
.SH SYNOPSIS |
| 15 |
\fBglobal \fR?\fIvarname ...\fR? |
| 16 |
.BE |
| 17 |
.SH DESCRIPTION |
| 18 |
.PP |
| 19 |
This command has no effect unless executed in the context of a proc body. |
| 20 |
If the \fBglobal\fR command is executed in the context of a proc body, it |
| 21 |
creates local variables linked to the corresponding global variables (though |
| 22 |
these linked variables, like those created by \fBupvar\fR, are not included |
| 23 |
in the list returned by \fBinfo locals\fR). |
| 24 |
.PP |
| 25 |
If \fIvarname\fR contains namespace qualifiers, the local variable's name is |
| 26 |
the unqualified name of the global variable, as determined by the |
| 27 |
\fBnamespace tail\fR command. |
| 28 |
.PP |
| 29 |
\fIvarname\fR is always treated as the name of a variable, not an |
| 30 |
array element. An error is returned if the name looks like an array element, |
| 31 |
such as \fBa(b)\fR. |
| 32 |
.SH EXAMPLES |
| 33 |
.PP |
| 34 |
This procedure sets the namespace variable \fI::a::x\fR |
| 35 |
.PP |
| 36 |
.CS |
| 37 |
proc reset {} { |
| 38 |
\fBglobal\fR a::x |
| 39 |
set x 0 |
| 40 |
} |
| 41 |
.CE |
| 42 |
.PP |
| 43 |
This procedure accumulates the strings passed to it in a global |
| 44 |
buffer, separated by newlines. It is useful for situations when you |
| 45 |
want to build a message piece-by-piece (as if with \fBputs\fR) but |
| 46 |
send that full message in a single piece (e.g. over a connection |
| 47 |
opened with \fBsocket\fR or as part of a counted HTTP response). |
| 48 |
.PP |
| 49 |
.CS |
| 50 |
proc accum {string} { |
| 51 |
\fBglobal\fR accumulator |
| 52 |
append accumulator $string \en |
| 53 |
} |
| 54 |
.CE |
| 55 |
.SH "SEE ALSO" |
| 56 |
namespace(n), upvar(n), variable(n) |
| 57 |
.SH KEYWORDS |
| 58 |
global, namespace, procedure, variable |