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

1
  • 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? Commented Jan 18, 2017 at 10:31

1 Answer 1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.