basic Tcl -- printing a value of variable

user2009590 picture user2009590 · Jan 25, 2013 · Viewed 8.6k times · Source

I have the following script in Tcl:

set val(a) 10
set val(b) 10
set val(n) expr{$val(a) * $val(b)}

How to print the value of the variable n?

puts $val(n)

gives expr{10*10} and i need to see 100....

Answer

Bryan Oakley picture Bryan Oakley · Jan 25, 2013

In order to evaluate an expression and return the results, you must put the eval command inside square brackets, rather than try to call it like a function:

set val(n) [expr {$val(a) * $val(b)}]
puts $val(n)