Reputation: 2279
I am working on main script that is souring a file eg
foo.tcl
In foo.tcl
, we have some array
variable declare
eg
array set foo {
"john" "doe"
"alpha" "beta"
}
In the main script we are trying to access the value using the key of array
source foo.tcl
set key "john"
puts ${::foo($key)} ;# can't read "::foo($key)": no such element in array
puts ${::foo(john)} ;# not giving error
How to access pass the dynamic key to the array?
Upvotes: 1
Views: 184
Reputation: 16438
You can use
puts $::foo($key)
Within braces, substitution won't happen.
Upvotes: 3