Variables In TCL

 Variable is a lifeline for a programming language. It provides a mechanism to a programming language to name a portion of a memory and reference a data stored there. 

We use assignment operation to set a particular value to a variable. In TCL, we use set command for assignment. we can use set command in two ways.

set pi 3.14;   # assigning a value (case 1)

set pi;  # reading a variable (case 2)

In Hello TCL, we get introduced to TCL language.

In case 1, a variable named pi is being assigned a value 3.14. We can also assign a string to a variable. After assigning a value to a variable, set command returns the value. In this example, 3.14.

In case 2, set command merely returns the value assigned to this variable. In this example, 3.14. Another way to read the value of a variable is prefixing the variable with $ e.g. $pi. Here is an example,

puts $pi

Here we are going to write a file named variable.tcl and then we will run it as, tclsh variable.tcl 

# Assign a value to a variable
set pi 3.14;
# Assign a string to a variable
set str "I am a string";
# Reading a variable
set pi;
# Displaying the value of a variable
puts $str;

If you are a bit confused or puzzled because set command returns the value but not showing in this example. In the near future you will find the answer.

Happy reading and thank you. Meet you soon.

Comments

Popular posts from this blog

Bash Shell In Linux

Creating An Animation Using A Text Editor

expr command In TCL