for loop - Tcl script to correct my output -


i have written tcl code gives me output below. close need. code:

for { set row 0 } { $row < 3 } {incr row } { set row[expr {$row + 1}] [lindex $sub_list $row] puts "row[expr {$row + 1}] [lindex $sub_list $row]" set pattern_number [llength [lindex $sub_list $row]] puts "pattern_number = $pattern number" set pattern_index [lindex $sub_list $row]      {set p 0} { $p < $pattern_number} {incr p} {       set pattern[expr {$p + 1}] [lindex $pattern_index $p]       puts "pattern[expr {$p + 1}] [lindex $pattern_index $p]"     }  } 

output of above code:

row1 b c d pattern number = 4 pattern1 pattern2 b pattern3 c pattern4 d  row2 p q r s pattern number = 4 pattern1 p pattern2 q pattern3 r pattern4 s  row3 w x y  pattern number = 3 pattern1 w pattern2 x pattern3 y 

instead, want code give me output follows:

row1 b c d pattern number = 4 pattern1 pattern2 b pattern3 c pattern4 d  row2 p q r s pattern number = 4 pattern5 p pattern6 q pattern7 r pattern8 s  row3 w x y  pattern number = 3 pattern9 w pattern10 x pattern11 y 

please suggest should do

  1. use foreach
  2. don't reset variable

so code becomes:

set rownr 0 set patnr 0 foreach row $sub_list {     incr rownr     puts "row$rownr $row"     puts "pattern number = [llength $row]"     foreach pattern $row {         incr patnr         puts "pattern$patnr $pattern"     } } 

if want process further, let me know how need that.
(i assume don't want generate variable names on fly.)


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -