1 | '\" |
---|
2 | '\" Copyright (c) 1993 The Regents of the University of California. |
---|
3 | '\" Copyright (c) 1994-1996 Sun Microsystems, Inc. |
---|
4 | '\" |
---|
5 | '\" See the file "license.terms" for information on usage and redistribution |
---|
6 | '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
7 | '\" |
---|
8 | '\" RCS: @(#) $Id: set.n,v 1.9 2007/12/13 15:22:33 dgp Exp $ |
---|
9 | '\" |
---|
10 | .so man.macros |
---|
11 | .TH set n "" Tcl "Tcl Built-In Commands" |
---|
12 | .BS |
---|
13 | '\" Note: do not modify the .SH NAME line immediately below! |
---|
14 | .SH NAME |
---|
15 | set \- Read and write variables |
---|
16 | .SH SYNOPSIS |
---|
17 | \fBset \fIvarName \fR?\fIvalue\fR? |
---|
18 | .BE |
---|
19 | .SH DESCRIPTION |
---|
20 | .PP |
---|
21 | Returns the value of variable \fIvarName\fR. |
---|
22 | If \fIvalue\fR is specified, then set |
---|
23 | the value of \fIvarName\fR to \fIvalue\fR, creating a new variable |
---|
24 | if one does not already exist, and return its value. |
---|
25 | If \fIvarName\fR contains an open parenthesis and ends with a |
---|
26 | close parenthesis, then it refers to an array element: the characters |
---|
27 | before the first open parenthesis are the name of the array, |
---|
28 | and the characters between the parentheses are the index within the array. |
---|
29 | Otherwise \fIvarName\fR refers to a scalar variable. |
---|
30 | .PP |
---|
31 | If \fIvarName\fR includes namespace qualifiers |
---|
32 | (in the array name if it refers to an array element), or if \fIvarName\fR |
---|
33 | is unqualified (does not include the names of any containing namespaces) |
---|
34 | but no procedure is active, |
---|
35 | \fIvarName\fR refers to a namespace variable |
---|
36 | resolved according to the rules described under \fBNAME RESOLUTION\fR in |
---|
37 | the \fBnamespace\fR manual page. |
---|
38 | .PP |
---|
39 | If a procedure is active and \fIvarName\fR is unqualified, then |
---|
40 | \fIvarName\fR refers to a parameter or local variable of the procedure, |
---|
41 | unless \fIvarName\fR was declared to resolve differently through one of the |
---|
42 | \fBglobal\fR, \fBvariable\fR or \fBupvar\fR commands. |
---|
43 | .SH EXAMPLES |
---|
44 | Store a random number in the variable \fIr\fR: |
---|
45 | .CS |
---|
46 | \fBset\fR r [expr {rand()}] |
---|
47 | .CE |
---|
48 | .PP |
---|
49 | Store a short message in an array element: |
---|
50 | .CS |
---|
51 | \fBset\fR anAry(msg) "Hello, World!" |
---|
52 | .CE |
---|
53 | .PP |
---|
54 | Store a short message in an array element specified by a variable: |
---|
55 | .CS |
---|
56 | \fBset\fR elemName "msg" |
---|
57 | \fBset\fR anAry($elemName) "Hello, World!" |
---|
58 | .CE |
---|
59 | .PP |
---|
60 | Copy a value into the variable \fIout\fR from a variable whose name is |
---|
61 | stored in the \fIvbl\fR (note that it is often easier to use arrays in |
---|
62 | practice instead of doing double-dereferencing): |
---|
63 | .CS |
---|
64 | \fBset\fR in0 "small random" |
---|
65 | \fBset\fR in1 "large random" |
---|
66 | \fBset\fR vbl in[expr {rand() >= 0.5}] |
---|
67 | \fBset\fR out [\fBset\fR $vbl] |
---|
68 | .CE |
---|
69 | .SH "SEE ALSO" |
---|
70 | expr(n), global(n), namespace(n), proc(n), trace(n), unset(n), upvar(n), variable(n) |
---|
71 | .SH KEYWORDS |
---|
72 | read, write, variable |
---|