tcl Variables Assigning values to variables


The command set is used to assign values in Tcl. When it is called with two arguments in the following manner,

% set tempVar "This is a string."
This is a string.

it places the second argument ("This is a string.") in the memory space referenced by the first argument (tempVar). set always returns the contents of the variable named in the first argument. In the above example, set would return "This is a string." without the quotes.

  • If value is specified, then the contents of the variable varName are set equal to value.
  • If varName consists only of alphanumeric characters, and no parentheses, it is a scalar variable.
  • If varName has the form varName(index), it is a member of an associative array.

Note that the name of the variable is not restricted to the Latin alphabet, it may consist of any combination of unicode characters (e.g. Armenian):

% set տուն house
% puts ${տուն}