0

I am taking an array and printing its values using tcl scripts but when I run the script is says can't read "ipname(0)": no such element in array

Here is the code I am using

array set ipname {UART TEST SPI I2C}
set asize 4
for {set i 0} {$i < $asize} {incr i}  {
      puts "$ipname($i) "
}
0

1 Answer 1

0

Your array set command doesn't do what you think. Essentially, it is as if you defined it as follows:

ipname("UART") = "TEST"
ipname("SPI") = "I2C"

What you want is

set ipname(0) "UART"
set ipname(1) "TEST"
set ipname(2) "SPI"
set ipname(3) "I2C"

or

array set ipname {0 UART 1 TEST 2 SPI 3 I2C}

See the documentation for Tcl arrays: http://tcl.tk/man/tcl8.5/TclCmd/array.htm

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.