Forum Discussion
iApp table parsing issue
According to the iApp wiki page Working with Tables it says that you can use the array set command with a lindexed value from a table variable -
array set columns [lindex $row 0]
So experimenting with this in tclsh I set a test variable -
% set test "{{
address 10.0.0.1
port 80
}} {{
address 10.0.0.2
port 80
}} {{
address 10.0.0.3
port 80
}}"
Now the result of [lindex $test 0] is this -
% lindex $test 0
{
address 10.0.0.1
port 80
}
Which is the desired result as the article explains.
However, when I try this on TCL you get an error -
% array set a1 [lindex $test 0]
list must have an even number of elements
In order to make it work I have to remove the curly brackets -
% array set a1 [string map {"{" "" "}" ""} [lindex $test 0]]
% parray a1
a1(address) = 10.0.0.1
a1(port) = 80
Am I doing something wrong or is the article wrong ?
The "Working with Tables" example shows a variable $row that contains 1 row of the table. In your example, the variable $test contains the entire table. If you want a single statement that operates on $test, it would be either
or%array set a1 [lindex [lindex $test 0] 0]%array set a1 [join [lindex $test 0]]
2 Replies
- Fred_Slater_856Historic F5 Account
The "Working with Tables" example shows a variable $row that contains 1 row of the table. In your example, the variable $test contains the entire table. If you want a single statement that operates on $test, it would be either
or%array set a1 [lindex [lindex $test 0] 0]%array set a1 [join [lindex $test 0]] - Eric_Flores_131
Cirrostratus
I see how they did it now. They are using a foreach loop which will remove the first set of curly brackets then the
removes the last set. When trying to use it in my iApps I am using a for loop which means I need to do the first lindex for the $test index then lindex 0 the result-lindex $row 0% for {set index 0} {$index < [llength $test]} {incr index} { puts "----------------------------------" array set a1 [lindex [lindex $test $index] 0] parray a1 } ---------------------------------- a1(address) = 10.0.0.1 a1(port) = 80 ---------------------------------- a1(address) = 10.0.0.2 a1(port) = 80 ---------------------------------- a1(address) = 10.0.0.3 a1(port) = 80
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
