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

SEE ALSO

55       expr(n),   global(n),   namespace(n),   proc(n),   trace(n),  unset(n),
56       upvar(n), variable(n)
57

KEYWORDS

59       read, write, variable
60
61
62
63Tcl                                                                     set(n)
Impressum