## Tcl9.0.3/Tk9.0.3 Documentation > Tcl Commands > global

### Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API

### NAME

global — 大域変数を利用する Access global variables

### 構文 SYNOPSIS

global ?varname ...?

### 説明 DESCRIPTION

この命令は､手続函数 の本体の文脈で実行しない限り効果がない｡もし､global 命令が手続函数の本体の文脈で実行されると､対応する大域変数に連結した局所変数を創造する(この連結された変数は､ upvar によって創造されたものと同じ様に､ info locals から返るリストの中には含まれない)｡ This command has no effect unless executed in the context of a proc body. If the global 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 upvar, are not included in the list returned by info locals).

もし､ varname に名前空間修飾子が含まれている場合は､その局所変数の名前は､ namespace tail 命令に決定された様に､修飾されない大域変数の名前になる｡ If varname contains namespace qualifiers, the local variable's name is the unqualified name of the global variable, as determined by the namespace tail command.

varname は常に変数名として扱われ､配列要素としては扱われない｡もし､a(b) の如く配列要素に見えると不都合が返る｡ 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 a(b).

### EXAMPLES

この手続函数は､名前空間変数 ::a::x を設定する This procedure sets the namespace variable ::a::x

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

この手続函数は､渡された文字列を大域緩衝領域中に改行記号で隔てて蓄積する｡伝言を細切れに作成しておき(恰も puts を使うが如くに)､全文を一気に送りたい時に有用である(譬えば､socket を使って開いた接続や､ 数えられたHTTP 応答の部分として)｡ 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 puts) but send that full message in a single piece (e.g. over a connection opened with socket or as part of a counted HTTP response).

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

### SEE ALSO

namespace, upvar, variable

### KEYWORDS

global, namespace, procedure, variable
Copyright © 1993 The Regents of the University of California.
Copyright © 1994-1997 Sun Microsystems, Inc.