0

I have list of objects in a variable stored as $m_objs using each object i can get 4 different values like demoRoot demoSuite demoCase and ic so each of those has to be a list of list like this:

set data {
    {demoRoot1 demoSuite1 demoCase1 ic1}
    {demoRoot2 demoSuite2 demoCase2 ic2}
    {demoRoot3 demoSuite3 demoCase3 ic3}
    {demoRoot4 demoSuite4 demoCase4 ic4}
    {demoRoot5 demoSuite5 demoCase5 ic5}
    {demoRoot5 demoSuite5 demoCase5 ic5}
}

So i tried using foreach loop like this:

set tests [list]

foreach ic $m_ics \
{
    set icRoot [$ic getRoot]
    set icSuite [$ic getSuite]
    set icCase [$ic getCase]
    set icName [$ic getName]
    set icList "$icRoot $icSuite $icCase $icName"
    lappend tests $icList
}

Output i get is for only one iteration like this

puts $icList
PTSE2 actions misc rmon_counters

but the Output should be obtained as i mentioned as set data {...........}

Please help me to get this one

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
vinay
  • 53
  • 1
  • 8
  • 1
    The `puts` is only printing the value for one iteration (the last one). The list of lists is built in the `tests` variable; try printing that? – Donal Fellows Jan 18 '17 at 10:31

1 Answers1

2

Change this line:

set icList "$icRoot $icSuite $icCase $icName"

to:

set icList [list $icRoot $icSuite $icCase $icName]

This will create icList as a list rather than a string, and will be appended to the tests list as a list.

References: list

Brad Lanam
  • 5,192
  • 2
  • 19
  • 29