manchal
Newbie level 6
set xy [list a b c]
#set xy "{a b c {cd de {efg fgh}}} 1 2 {34 45 {567 678}}"
puts "$xy"
set l [ llength $xy ]
set j 0
puts "the index:"
#the proc of index
proc indx {x i {k ""}} {
set len [ llength $x ]
for {} {$i<$len} {incr i} {
set aa [lindex $x $i]
set b [llength $x]
if {($b == 1) && ($k == "")} {
return "[lindex $x $i ]-->$i $i"
} elseif {($b == 1)} {
return "[lindex $x $i ]-> $k- $i"
} else {
set s $i
if {$k != ""} {set s "$k-$s"}
return "[indx $aa $s]"
}
}
} ; #end of Proc
for {set m 0} {$m<$l} {incr m} {
set ak [indx $xy $j ] #updatng the valu evrytme proc is called.It updates the val only once.
#set j [lindex $ak 1]
puts "$j"
incr j
puts "$ak"
}
output:
a b c
the index:
0
a-->0 0
1
2
wanted as
0
a->0
1
b->1
2
c->2
#set xy "{a b c {cd de {efg fgh}}} 1 2 {34 45 {567 678}}"
puts "$xy"
set l [ llength $xy ]
set j 0
puts "the index:"
#the proc of index
proc indx {x i {k ""}} {
set len [ llength $x ]
for {} {$i<$len} {incr i} {
set aa [lindex $x $i]
set b [llength $x]
if {($b == 1) && ($k == "")} {
return "[lindex $x $i ]-->$i $i"
} elseif {($b == 1)} {
return "[lindex $x $i ]-> $k- $i"
} else {
set s $i
if {$k != ""} {set s "$k-$s"}
return "[indx $aa $s]"
}
}
} ; #end of Proc
for {set m 0} {$m<$l} {incr m} {
set ak [indx $xy $j ] #updatng the valu evrytme proc is called.It updates the val only once.
#set j [lindex $ak 1]
puts "$j"
incr j
puts "$ak"
}
output:
a b c
the index:
0
a-->0 0
1
2
wanted as
0
a->0
1
b->1
2
c->2
Last edited: