kiran Biradar
kiran Biradar

Reputation: 12742

Associated array with list in tcl

I'm beginner in TCL scripting and I'm trying to store list as part of associated array as below.

script:

set cellno 0
set red redcolor
set green greencolor
set blue bluecolor

set myVariable($cellno) {$red $green $blue}

puts [lindex $myVariable($cellno) 2]

problem:

For some reason puts [lindex $myVariable($cellno) 2] is displaying value as below

 $blue

Instead of

 bluecolor

Upvotes: 0

Views: 113

Answers (1)

Andreas
Andreas

Reputation: 5301

This line:

set myVariable($cellno) {$red $green $blue}

...does not substitute the color variables since they are in braces. You could use double quotes:

set myVariable($cellno) "$red $green $blue"

Since you use it as a list using lindex, prefer list to avoid unintentional word splitting (and merging in case of empty string or whitespace only variables):

set myVariable($cellno) [list $red $green $blue]

Upvotes: 3

Related Questions