Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variables -another question

Status
Not open for further replies.

ee1

Programmer
May 31, 2011
25
IL
Hi,
suppose i have 3 variables:
var_a
var_b
var_c

and i have another variable for selection (a/b/c):
select

how should io write in order to get the value from var_a,var_b, var_c?

i tried:
${var_{$select}}

but it doesnt work...
 
thanks,
is this syntax works for array too?

i mean:
i have array: array_a, array_b...
i want to read a value, so:

[set "array_$select($value)"]
?
 
so whats the way to read an array (with variable in its name)?
array_$select($value)

thanks.
 
IMHO, using indirect variables is not very good.
Instead of it you can use hashes:
1. instead of this
Code:
set var_value [set "var_$select"]
I would rather use hash my_vars defined like
{'a' => 'value_of_a',
'b' => 'value_of_b',
...
}

2. instead of indirect hash like
Code:
array_$select($value)
I would try to use a hash which elements are hashes.
 
Hi

mikrom said:
I would try to use a hash which elements are hashes.
Sad, but that is not supported.

The best workaround is to fake it including a separator in the keys, somehow similar to Awk :
Code:
array [b]set[/b] dial [teal]{[/teal] [teal]}[/teal]

[b]set[/b] label [purple]0[/purple]
[b]foreach[/b] vertical [teal]{[/teal] top center bottom [teal]}[/teal] [teal]{[/teal]
  [b]foreach[/b] horizontal [teal]{[/teal] left center right [teal]}[/teal] [teal]{[/teal]
    [b]set[/b] dial[teal]([/teal][navy]$vertical[/navy][teal],[/teal][navy]$horizontal[/navy][teal])[/teal] [teal][[/teal][b]incr[/b] label[teal]][/teal]
  [teal]}[/teal]
[teal]}[/teal]

[b]puts[/b] [green][i]"The center right button on the dial is $dial(center,right)"[/i][/green]

[b]puts[/b] [green][i]"Buttons in the dial's left column are :"[/i][/green]
[b]foreach[/b] [teal]{[/teal]key label[teal]}[/teal] [teal][[/teal]array get dial [teal]{[/teal][teal]*,[/teal]left[teal]}[/teal][teal]][/teal] [teal]{[/teal] [b]puts[/b] [green][i]" - $label ( $key )"[/i][/green] [teal]}[/teal]

Feherke.
 
OK, I guess, that I have done something like this in Perl or Python, but never tried it in Tcl :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top