| 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 | '\" RCS: @(#) $Id: global.n,v 1.12 2007/12/13 15:22:32 dgp Exp $ | 
|---|
| 9 | '\"  | 
|---|
| 10 | .so man.macros | 
|---|
| 11 | .TH global n "" Tcl "Tcl Built-In Commands" | 
|---|
| 12 | .BS | 
|---|
| 13 | '\" Note:  do not modify the .SH NAME line immediately below! | 
|---|
| 14 | .SH NAME | 
|---|
| 15 | global \- Access global variables | 
|---|
| 16 | .SH SYNOPSIS | 
|---|
| 17 | \fBglobal \fIvarname \fR?\fIvarname ...\fR? | 
|---|
| 18 | .BE | 
|---|
| 19 |  | 
|---|
| 20 | .SH DESCRIPTION | 
|---|
| 21 | .PP | 
|---|
| 22 | This command has no effect unless executed in the context of a proc body. | 
|---|
| 23 | If the \fBglobal\fR command is executed in the context of a proc body, it | 
|---|
| 24 | creates local variables linked to the corresponding global variables (and | 
|---|
| 25 | therefore these variables are listed by info locals). | 
|---|
| 26 | .PP | 
|---|
| 27 | If \fIvarname\fR contains namespace qualifiers, the local variable's name is | 
|---|
| 28 | the unqualified name of the global variable, as determined by the | 
|---|
| 29 | \fBnamespace tail\fR command.  | 
|---|
| 30 | .PP | 
|---|
| 31 | \fIvarname\fR is always treated as the name of a variable, not an | 
|---|
| 32 | array element.  An error is returned if the name looks like an array element, | 
|---|
| 33 | such as \fBa(b)\fR. | 
|---|
| 34 | .SH EXAMPLES | 
|---|
| 35 | This procedure sets the namespace variable \fI::a::x\fR | 
|---|
| 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 | .CS | 
|---|
| 49 | proc accum {string} { | 
|---|
| 50 |     \fBglobal\fR accumulator | 
|---|
| 51 |     append accumulator $string \en | 
|---|
| 52 | } | 
|---|
| 53 | .CE | 
|---|
| 54 |  | 
|---|
| 55 | .SH "SEE ALSO" | 
|---|
| 56 | namespace(n), upvar(n), variable(n) | 
|---|
| 57 |  | 
|---|
| 58 | .SH KEYWORDS | 
|---|
| 59 | global, namespace, procedure, variable | 
|---|