Re: Dynamic variables and lists



ssriperu1@xxxxxxxxx wrote:
Here's my problem:

% set a power
power
% set ${a} [list a b c d]
a b c d
% set second [lindex ${a} 1]

Since a contains "power", the above is identical to:

    set second [lindex "power" 1]

% puts $second
# prints nothing

.... because "power", when treated like a list, has only 1 element.

% set second [lindex eval ${$a} 1]

The above is wrong on many levels. Read the man page on lindex and you'll see that the first argument is the list to be operated on. In the above you're looking into a list that contains the word "eval". Not what you indented, I'm sure.



can't read "$a": no such variable

That is because there is no variable named "$a" (dollar sign, letter a)

% puts $a
power

Correct. The variable "a" (*not* the variable $a) contains the word "power"

% set second [lindex eval $a 1]
bad index "power": must be integer or end?-integer?

Again, look up the definition of the lindex command.


How do I get access to the $power list without specifying "power" ?

how about set second [lindex [set $a] 1]

Remember that 'set' returns the value of the variable. Also remember that tcl does substitution before calling a command. Thus, [set $a] in this case is identical to [set power], which gives the value stored in the variable named "power".

Since you are just now learning tcl I strongly recommend you do not try to use dynamic variables. Try using an array, they are much easier to use:

    set a "power"
    set data($a) [list a b c d]
    set second [lindex $data($a) 1]
.



Relevant Pages

  • Re: printuientry
    ... If the printer was created with a "Local Port", it will show up in the ... open a command prompt and issue the commands: ... > When im logged on as network administrator, ...
    (microsoft.public.win2000.printing)
  • Re: asrock, problem with nic after windows-boot - Exact Opposite issue the OP is having
    ... Yup - just like the switch on the power strip that you used instead (so you ... 0xFFFFFFF0 address, but the /RESET line isn't asserted, so the hardware ... and another command to learn is 'grep' and 'zgrep' (which handles compressed ... HTML ...
    (comp.os.linux.networking)
  • Re: IE Explorer 6.0 Locking Up On A Web Page Account
    ... Thanks, I will try that running that command again, it didn't work when I ... Connection May No Longer Be Needed was checked, so I uncheck it. ... computer turn OFF this device for Power saving. ... winsock reset command and then reboot the system. ...
    (microsoft.public.windowsxp.general)
  • Re: Inadvertent Cable Cutter Firing
    ... > ISS has similar command protection, ... > upstream, then remove the close-inhibit for the power RPC, and then close ... > that power RPC to get the whole thing to fire. ... temperature might disrupt thrittle control for engines etc etc. ...
    (sci.space.station)
  • Re: Power saving issues
    ... I really didn't want the output for the command: 'powercfg /?' ... not an ACPI (Advanced Configuration and Power Interface) it may not support ... - Go into the BIOS setup program and check the power settings ...
    (microsoft.public.windowsxp.general)