Daniel Wang
Daniel Wang

Reputation: 11

Getting value from TCL variable

I have a line in TCL:

set val A_$Name*10 

where

$Name = "B"

When I do:

puts $val

I get

"A_B*10"

How can I get the actual value of A_B * 10? Thanks

Upvotes: 0

Views: 706

Answers (1)

Chris Heithoff
Chris Heithoff

Reputation: 1873

You can't do math operators in the set assignment like that. Use the expr command to do that.

You are also doing a double substitution. First from Name to B, second from A_B to its value. Using set with one argument, to get the value of the var name, is a nice way to do double substitution.

set A_B 10
set Name B

set val [expr [set A_$Name] * 10]    --> 100

Upvotes: 3

Related Questions