Skip to content
Tcl Source Code Artifact [e61298ff35]
Login

Artifact [e61298ff35]

Artifact e61298ff353d2326e5cfba2ce404edd73f2c7e7518a6ebbdeceb02fd4b73e18c:



CommandName: global ManualSection: n Version: unknown TclPart: Tcl TclDescription: Tcl Built-In Commands Links:

Name

global - Access global variables

Synopsis

::: {.synopsis} ::: [global]{.cmd} [varname]{.optdot} :::

Description

This command has no effect unless executed in the context of a proc body. If the fBglobalfR command is executed in the context of a proc body, it creates local variables linked to the corresponding global variables (though these linked variables, like those created by fBupvarfR, are not included in the list returned by fBinfo localsfR).

If fIvarnamefR contains namespace qualifiers, the local variable's name is the unqualified name of the global variable, as determined by the fBnamespace tailfR command.

varname is always treated as the name of a variable, not an array element. An error is returned if the name looks like an array element, such as fBa(b)fR.

Examples

This procedure sets the namespace variable fI::a::xfR

proc reset {} {
    global a::x
    set x 0
}

This procedure accumulates the strings passed to it in a global buffer, separated by newlines. It is useful for situations when you want to build a message piece-by-piece (as if with fBputsfR) but send that full message in a single piece (e.g. over a connection opened with fBsocketfR or as part of a counted HTTP response).

proc accum {string} {
    global accumulator
    append accumulator $string \n
}