set a {a b {c {d e} h} i}
set glob_var {}
proc list_eval {list_name {prefix {}}} {
global glob_var
set end_point [expr [llength $list_name] -1]
for {set start_point 0} {$start_point <= $end_point} {incr start_point} {
if {[llength [lindex $list_name $start_point]] == 1} {
puts “Index for [lindex $list_name $start_point] is $prefix$start_point”
if {$start_point == $end_point} {
set glob_var [string range $glob_var 0 end-1]
}
} else {
append glob_var $start_point
list_eval [lindex $list_name $start_point] $glob_var
}
}
}
list_eval $a
Output will be:
Index for a is 0
Index for b is 1
Index for c is 20
Index for d is 210
Index for e is 211
Index for h is 22
Index for i is 3
Advertisement