From: CKL on 12 Mar 2010 16:23 Hello tcl gurus I'm sure that the question has already been asked a lot of times, but it's difficult to find the right syntax to find an answer to my question So I ask it again #let following variable. set a(3) "My variable" # Now another way set index "(3)" set base "a" set var $base$index puts $var a(3) # What I want is now $a(3) which should give me "My Variable" puts $$var $a(3) Has anybody a solution Thanks in advance Christian
From: Prof Craver on 12 Mar 2010 16:42 On Mar 12, 4:23 pm, CKL <christian.klugesh...(a)gmail.com> wrote: > > > # What I want is now $a(3) which should give me "My Variable" > > puts $$var > $a(3) > > Has anybody a solution Try puts [set $var] instead of puts $$var. You could also simply write puts [set $base$index] Note that if you instead {set index 3} instead of {set index (3)}, the interpreter will barf at you for writing {puts [set $base($index)]}; you must instead write {puts [set ${base}($index)]}. --S
From: Bryan Oakley on 12 Mar 2010 16:46 On Mar 12, 3:23 pm, CKL <christian.klugesh...(a)gmail.com> wrote: > Hello tcl gurus > > I'm sure that the question has already been asked a lot of times, but > it's difficult to find the right syntax to find an answer to my > question > So I ask it again > > #let following variable. > set a(3) "My variable" > > # Now another way > set index "(3)" > set base "a" > set var $base$index > puts $var > a(3) > > # What I want is now $a(3) which should give me "My Variable" > > puts $$var > $a(3) > > Has anybody a solution The short answer (and others will probably give a long explanation so I'll avoid the temptation) is: puts [set $var] But... don't do that. It is soooooooo much easier to use arrays: set var($base,$index) "My Variable" ... puts $var($base,$index) Arrays are much easier to deal with than dynamic variable names.
From: CKL on 12 Mar 2010 17:05 On 12 mar, 22:46, Bryan Oakley <oak...(a)bardo.clearlight.com> wrote: > On Mar 12, 3:23 pm, CKL <christian.klugesh...(a)gmail.com> wrote: > > > > > Hello tcl gurus > > > I'm sure that the question has already been asked a lot of times, but > > it's difficult to find the right syntax to find an answer to my > > question > > So I ask it again > > > #let following variable. > > set a(3) "My variable" > > > # Now another way > > set index "(3)" > > set base "a" > > set var $base$index > > puts $var > > a(3) > > > # What I want is now $a(3) which should give me "My Variable" > > > puts $$var > > $a(3) > > > Has anybody a solution > > The short answer (and others will probably give a long explanation so > I'll avoid the temptation) is: > > puts [set $var] > > But... don't do that. It is soooooooo much easier to use arrays: > > set var($base,$index) "My Variable" > ... > puts $var($base,$index) > > Arrays are much easier to deal with than dynamic variable names. Thanks to all Regards Christian
|
Pages: 1 Prev: building Tkpng package Next: Regular expression library from Google |