1set(n)                       Tcl Built-In Commands                      set(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       set - Read and write variables
9

SYNOPSIS

11       set varName ?value?
12______________________________________________________________________________
13

DESCRIPTION

15       Returns the value of variable varName.  If value is specified, then set
16       the value of varName to value, creating a new variable if one does  not
17       already  exist,  and  return  its  value.   If varName contains an open
18       parenthesis and ends with a close parenthesis, then  it  refers  to  an
19       array  element:   the  characters before the first open parenthesis are
20       the name of the array, and the characters between the  parentheses  are
21       the index within the array.  Otherwise varName refers to a scalar vari‐
22       able.
23
24       If varName includes namespace qualifiers  (in  the  array  name  if  it
25       refers  to  an  array  element), or if varName is unqualified (does not
26       include the names of any containing namespaces)  but  no  procedure  is
27       active,  varName  refers  to a namespace variable resolved according to
28       the rules described under NAME RESOLUTION in the namespace manual page.
29
30       If a procedure is active  and  varName  is  unqualified,  then  varName
31       refers  to  a parameter or local variable of the procedure, unless var‐
32       Name was declared to resolve differently through  one  of  the  global,
33       variable or upvar commands.
34

EXAMPLES

36       Store a random number in the variable r:
37
38              set r [expr {rand()}]
39
40       Store a short message in an array element:
41
42              set anAry(msg) "Hello, World!"
43
44       Store a short message in an array element specified by a variable:
45
46              set elemName "msg"
47              set anAry($elemName) "Hello, World!"
48
49       Copy a value into the variable out from a variable whose name is stored
50       in the vbl (note that it is often easier  to  use  arrays  in  practice
51       instead of doing double-dereferencing):
52
53              set in0 "small random"
54              set in1 "large random"
55              set vbl in[expr {rand() >= 0.5}]
56              set out [set $vbl]
57

SEE ALSO

59       expr(n),   global(n),   namespace(n),   proc(n),   trace(n),  unset(n),
60       upvar(n), variable(n)
61

KEYWORDS

63       read, write, variable
64
65
66
67Tcl                                                                     set(n)
Impressum