How to Print the Contents of an Array in Tcl

后端 未结 1 520
猫巷女王i
猫巷女王i 2021-01-11 20:07

I want to print the contents of an array in Tcl (for debugging). The order is unimportant, I just want every value printed.

How do I do it?

1条回答
  •  囚心锁ツ
    2021-01-11 20:15

    The simplest way would be to use parray:

    % array set val [list a 1 b 2 c 3]
    % parray val
    val(a) = 1
    val(b) = 2
    val(c) = 3
    

    If you want just the key and the value, well, use a loop and array get:

    foreach {key value} [array get val] {
        puts "$key => $value"
    }
    

    0 讨论(0)
提交回复
热议问题