The command in the previous example set the variable myvar
to
the string "27". The only data type in Tcl is a string. However,
some commands will interpret arguments as numbers, for example the
expr
command (expr
will be explained later).
To use the value of a variable, you prepend it with :
% puts myvar 27(
puts
is the command to print some value.)
String values are normally delimited with double quotes, but a string of a single word doesn't need them:
% set myvar "hello world!" hello world! % puts myvar hello
The value of a variable can be used when defining a string by prepending it
with a :
% set myvar "world!" world! % set myvar2 "hello myvar" hello world! % puts myvar2 hello world!
To include a literal 'world!
Variables are not declared, but come into existence as soon as they get a value:
% puts unknownvar knownA variable can be destroyed by unsetting it:
% puts unknownvar can't read "unknownvar": no such variable