Reputation:
I have a following long tcl list:
>> puts $res
{ banner { } } { report { { name {{ columns { {head1} {head2} {head3} {head4} {pin} } } { { row_1 { { } {-0.008} { } {r1} {hier1} } } { row_2 { {1000} {-0.009} {-0.000} {r2} {hier2} } } } } } } }
I need to access the value 1000 in row_2.
Though I am able to get the value using the following, I was wondering if there was a better way to do this rather than specifying lindex so many times.
>> set val [lindex [lindex [lindex [lindex [lindex [lindex [lindex [lindex $res 1] 1] 0] 1] 1] 1] 1] 0]
>> 1000
Upvotes: 0
Views: 100
Reputation: 4813
The lindex
command can take multiple indexes, so you can do:
set val [lindex $res 1 1 0 1 1 1 1 0]
Upvotes: 1