Eric_Flores_131
Oct 17, 2013Cirrostratus
Solved
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]]