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
14

DESCRIPTION

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

EXAMPLES

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

SEE ALSO

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

KEYWORDS

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