other languages
other sections
conflicting packages
set(3tcl) | Tcl Built-In Commands | set(3tcl) |
NAME¶
set - Read and write variablesSYNOPSIS¶
set varName ?value?DESCRIPTION¶
Returns the value of variable varName. If value is specified, then set the value of varName to value, creating a new variable if one does not already exist, and return its value. If varName contains an open parenthesis and ends with a close parenthesis, then it refers to an array element: the characters before the first open parenthesis are the name of the array, and the characters between the parentheses are the index within the array. Otherwise varName refers to a scalar variable. If varName includes namespace qualifiers (in the array name if it refers to an array element), or if varName is unqualified (does not include the names of any containing namespaces) but no procedure is active, varName refers to a namespace variable resolved according to the rules described under NAME RESOLUTION in the namespace manual page. If a procedure is active and varName is unqualified, then varName refers to a parameter or local variable of the procedure, unless varName was declared to resolve differently through one of the global, variable or upvar commands.EXAMPLES¶
Store a random number in the variable r:set r [expr {rand()}]
set anAry(msg) "Hello, World!"
set elemName "msg" set anAry($elemName) "Hello, World!"
set in0 "small random" set in1 "large random" set vbl in[expr {rand() >= 0.5}] set out [set $vbl]
SEE ALSO¶
expr(3tcl), global(3tcl), namespace(3tcl), proc(3tcl), trace(3tcl), unset(3tcl), upvar(3tcl), variable(3tcl)KEYWORDS¶
read, write, variableTcl |