foreach - tcl loop through multiple lists -
i have 2 lists i'd manipulate.. ( tcl newbie..). i'd associate these 2 lists , create third list data added.
the data have:
set aes {ae0 ae3 ae6 ae1v1 ae1v8} set c {c1 c2 c3 k1 k2} foreach $aes { foreach c $c { puts ${a}_$c } }
the data you'd expect is: ae0_c1 ae0_c2 ae0_c3 ae0_k1 ae0_k2 .. ..
what want append data in front of this.
ae-to-c = ae0_c1 ae0_c2 ae0_c3 ae0_k1 ae0_k2 .. end
.
% set aes {ae0 ae3 ae6 ae1v1 ae1v8} ae0 ae3 ae6 ae1v1 ae1v8 % set c {c1 c2 c3 k1 k2} c1 c2 c3 k1 k2 % foreach $aes { foreach c $c { # saving 'result' variable lappend result ${a}_${c} } } % set data "some more here" more here % set result ae0_c1 ae0_c2 ae0_c3 ae0_k1 ae0_k2 ae3_c1 ae3_c2 ae3_c3 ae3_k1 ae3_k2 ae6_c1 ae6_c2 ae6_c3 ae6_k1 ae6_k2 ae1v1_c1 ae1v1_c2 ae1v1_c3 ae1v1_k1 ae1v1_k2 ae1v8_c1 ae1v8_c2 ae1v8_c3 ae1v8_k1 ae1v8_k2 % set result [linsert $result 0 $data] more here ae0_c1 ae0_c2 ae0_c3 ae0_k1 ae0_k2 ae3_c1 ae3_c2 ae3_c3 ae3_k1 ae3_k2 ae6_c1 ae6_c2 ae6_c3 ae6_k1 ae6_k2 ae1v1_c1 ae1v1_c2 ae1v1_c3 ae1v1_k1 ae1v1_k2 ae1v8_c1 ae1v8_c2 ae1v8_c3 ae1v8_k1 ae1v8_k2
Comments
Post a Comment