Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

set(3tcl) [debian man page]

set(3tcl)						       Tcl Built-In Commands							 set(3tcl)

__________________________________________________________________________________________________________________________________________________

NAME
set - Read and write variables SYNOPSIS
set varName ?value? _________________________________________________________________ DESCRIPTION
Returns the value of variable varName. If value is specified, then set the value of varName to value, creating a new variable if one does not already exist, and return its value. If varName contains an open parenthesis and ends with a close parenthesis, then it refers to an array element: the characters before the first open parenthesis are the name of the array, and the characters between the parentheses are the index within the array. Otherwise varName refers to a scalar variable. If varName includes namespace qualifiers (in the array name if it refers to an array element), or if varName is unqualified (does not include the names of any containing namespaces) but no procedure is active, varName refers to a namespace variable resolved according to the rules described under NAME RESOLUTION in the namespace manual page. If a procedure is active and varName is unqualified, then varName refers to a parameter or local variable of the procedure, unless varName was declared to resolve differently through one of the global, variable or upvar commands. EXAMPLES
Store a random number in the variable r: set r [expr {rand()}] Store a short message in an array element: set anAry(msg) "Hello, World!" Store a short message in an array element specified by a variable: set elemName "msg" set anAry($elemName) "Hello, World!" Copy a value into the variable out from a variable whose name is stored in the vbl (note that it is often easier to use arrays in practice instead of doing double-dereferencing): set in0 "small random" set in1 "large random" set vbl in[expr {rand() >= 0.5}] set out [set $vbl] SEE ALSO
expr(3tcl), global(3tcl), namespace(3tcl), proc(3tcl), trace(3tcl), unset(3tcl), upvar(3tcl), variable(3tcl) KEYWORDS
read, write, variable Tcl set(3tcl)

Check Out this Related Man Page

variable(3tcl)						       Tcl Built-In Commands						    variable(3tcl)

__________________________________________________________________________________________________________________________________________________

NAME
variable - create and initialize a namespace variable SYNOPSIS
variable ?name value...? name ?value? _________________________________________________________________ DESCRIPTION
This command is normally used within a namespace eval command to create one or more variables within a namespace. Each variable name is initialized with value. The value for the last variable is optional. If a variable name does not exist, it is created. In this case, if value is specified, it is assigned to the newly created variable. If no value is specified, the new variable is left undefined. If the variable already exists, it is set to value if value is specified or left unchanged if no value is given. Normally, name is unqualified (does not include the names of any containing namespaces), and the variable is created in the current namespace. If name includes any namespace qualifiers, the variable is created in the specified names- pace. If the variable is not defined, it will be visible to the namespace which command, but not to the info exists command. If the variable command is executed inside a Tcl procedure, it creates local variables linked to the corresponding namespace variables (and therefore these variables are listed by info vars.) In this way the variable command resembles the global command, although the global command only links to variables in the global namespace. If any values are given, they are used to modify the values of the associated namespace variables. If a namespace variable does not exist, it is created and optionally initialized. A name argument cannot reference an element within an array. Instead, name should reference the entire array, and the initialization value should be left off. After the variable has been declared, elements within the array can be set using ordinary set or array commands. EXAMPLES
Create a variable in a namespace: namespace eval foo { variable bar 12345 } Create an array in a namespace: namespace eval someNS { variable someAry array set someAry { someName someValue otherName otherValue } } Access variables in namespaces from a procedure: namespace eval foo { proc spong {} { # Variable in this namespace variable bar puts "bar is $bar" # Variable in another namespace variable ::someNS::someAry parray someAry } } SEE ALSO
global(3tcl), namespace(3tcl), upvar(3tcl) KEYWORDS
global, namespace, procedure, variable Tcl 8.0 variable(3tcl)
Man Page