Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/set.n @ 25

Last change on this file since 25 was 25, checked in by landauf, 17 years ago

added tcl to libs

File size: 2.5 KB
Line 
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
15set \- Read and write variables
16.SH SYNOPSIS
17\fBset \fIvarName \fR?\fIvalue\fR?
18.BE
19.SH DESCRIPTION
20.PP
21Returns the value of variable \fIvarName\fR.
22If \fIvalue\fR is specified, then set
23the value of \fIvarName\fR to \fIvalue\fR, creating a new variable
24if one does not already exist, and return its value.
25If \fIvarName\fR contains an open parenthesis and ends with a
26close parenthesis, then it refers to an array element:  the characters
27before the first open parenthesis are the name of the array,
28and the characters between the parentheses are the index within the array.
29Otherwise \fIvarName\fR refers to a scalar variable.
30.PP
31If \fIvarName\fR includes namespace qualifiers
32(in the array name if it refers to an array element), or if \fIvarName\fR
33is unqualified (does not include the names of any containing namespaces)
34but no procedure is active,
35\fIvarName\fR refers to a namespace variable
36resolved according to the rules described under \fBNAME RESOLUTION\fR in
37the \fBnamespace\fR manual page.
38.PP
39If a procedure is active and \fIvarName\fR is unqualified, then
40\fIvarName\fR refers to a parameter or local variable of the procedure,
41unless \fIvarName\fR was declared to resolve differently through one of the
42\fBglobal\fR, \fBvariable\fR or \fBupvar\fR commands.
43.SH EXAMPLES
44Store a random number in the variable \fIr\fR:
45.CS
46\fBset\fR r [expr {rand()}]
47.CE
48.PP
49Store a short message in an array element:
50.CS
51\fBset\fR anAry(msg) "Hello, World!"
52.CE
53.PP
54Store 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
60Copy a value into the variable \fIout\fR from a variable whose name is
61stored in the \fIvbl\fR (note that it is often easier to use arrays in
62practice 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"
70expr(n), global(n), namespace(n), proc(n), trace(n), unset(n), upvar(n), variable(n)
71.SH KEYWORDS
72read, write, variable
Note: See TracBrowser for help on using the repository browser.