|
|
 |
 |
 |
 |
TCL(Tool Command Language) Scripting
|
 |
 |
 |
 |
 |
 |
 |
 |
tcl list name
Hello, If I have access to the name of a tcl list, how can I access the elements? I'm reading in a file that has the names of list variables. set lvar { 1 2 3} <--- don't have access to this set lname "lvar" <--- I have access to this only How do I display the values of lvar using lname? THANKS!
Hello, If I have access to the name of a tcl list, how can I access the elements? I'm reading in a file that has the names of list variables. set lvar { 1 2 3} <--- don't have access to this set lname "lvar" <--- I have access to this only How do I display the values of lvar using lname? THANKS!
ap wrote: > Hello, > If I have access to the name of a tcl list, how > can I access the elements? > I'm reading in a file that has the names of list variables. > set lvar { 1 2 3} <--- don't have access to this > set lname "lvar" <--- I have access to this only > How do I display the values of lvar using lname? > THANKS!
set lvar { 1 2 3} set lname "lvar" # this: set thislist [ set $lname ] # alternatively: upvar 0 $lname l_lvar set thislist $l_lvar uwe
On May 15, 12:18 pm, ap <cors@ragingbull.com> wrote: > Hello, > If I have access to the name of a tcl list, how > can I access the elements? > I'm reading in a file that has the names of list variables. > set lvar { 1 2 3} <--- don't have access to this > set lname "lvar" <--- I have access to this only > How do I display the values of lvar using lname? > THANKS!
If you: set lname $lvar $lname will have the same elements in its list as $lvar does. if you: puts $lvar that will show you what is in $lvar: (bin) 17 % set lvar {1 2 3} 1 2 3 (bin) 18 % set lname $lvar 1 2 3 (bin) 19 % puts $lvar 1 2 3 (bin) 20 % puts $lname 1 2 3 (bin) 21 % puts [llength $lvar] 3 (bin) 22 % puts [llength $lname] 3 (bin) 23 % Not sure what you are trying to do though...but I hope that helps. Robert
On May 15, 12:43 pm, Robert Hicks <sigz@gmail.com> wrote: > Not sure what you are trying to do though...but I hope that helps.
I suspect this is a need for redirection. % set var1 [list a b c] a b c % set ptr [list var1] var1 % puts $ptr var1 % puts [set $ptr] a b c % llength [set $ptr] 3
Hello, in tcl it is not that usual to say that a list has a name. But a list (data structure) is hold by a variable, which itself has a name. % set lvar [list 1 2 3]; # creating a list stored in the variable lvar 1 2 3 % set lvar; # accessing the variable lvar directly 1 2 3 % set foo [set lvar]; # using the contents of the variable lvar 1 2 3 % set foo $lvar; # direct "dereferencing" of the variable lvar 1 2 3 % lindex $lvar 0; # accessing the first element of the list inside the lvar 1 % set varName "lvar" lvar % set $varName; # accessing the variable lvar via the stored variable name 1 2 3 It happens not very often, that the name of a variable must be built dynamically, so that it is necessary to store the name of a variable in another variable to have "indirect" access to those values. If I say "not very often", than I don't mean, that there is no need for, but mostly in my applications there was no need and sometimes I was glad to be able to access variables "indirectly". Best regards, Martin Lemburg Siemens Automation and Drives - UGS PLM Software On May 15, 6:18 pm, ap <cors@ragingbull.com> wrote:
> Hello, > If I have access to the name of a tcl list, how > can I access the elements? > I'm reading in a file that has the names of list variables. > set lvar { 1 2 3} <--- don't have access to this > set lname "lvar" <--- I have access to this only > How do I display the values of lvar using lname? > THANKS!
In article <1179248000.914811.133@e65g2000hsc.googlegroups.com>, MartinLemburg@UGS <martin.lemburg. @gmx.net> wrote: . . . >It happens not very often, that the name of a variable must be built >dynamically, so that it is necessary to store the name of a variable >in another variable to have "indirect" access to those values. >If I say "not very often", than I don't mean, that there is no need >for, but mostly in my applications there was no need and sometimes I >was glad to be able to access variables "indirectly".
. . . ... and, as Martin knows, often when it does seem as though a "double dereferencing" is appropriate, a recoding in terms of an associative array (or dictionary) is even more so <URL: http://wiki.tcl.tk/8662 >.
|
 |
 |
 |
 |
|