Prev: open command
Next: foreach-loop for growing lists
From: yilmaz on 13 Jun 2010 15:02 On Jun 13, 9:47 pm, Sean Woods <y...(a)etoyoc.com> wrote: > On Jun 12, 5:37 am, yilmaz <yyyyil...(a)gmail.com> wrote: > > > > > > > Hi, Please help me with the following problem. I have very little > > experience with multidimensional arrays and need your advice. > > > I have several lists like below from files comp-1, comp-2, and comp-3: > > > {ADA} input {ft 0.23} {fg 0.9} {df 0.45} {gh 0.33} {hj 0.11} {jj > > 0.345} {gg 0.6} > > {DW} inout {ft 0.13} {fg 0.19} {df 0.5} {gh 0.2} {hj 0.14} {jj > > 0.53} {gg 0.31} > > .... > > > that will be converted into a table like below: > > > --------------------------------------------------------------------------- --------------------------------------------- > > | Comp-1 | > > Comp-2 | Comp-3 > > Items ------------------------------------ > > |------------------------- |--------------------------------- > > | ft fg df gh | ft fg > > df gh | ft fg df gh > > -------------------------------------------------- > > |-------------------------------------------------------------- > > ADA | 0.23 0.9 0.45 0.33 | 0.3 0.4 0.1 0.2 | > > 0.22 0.44 0.66 0.8 > > DW | 0.13 0.19 0.5 0.2 | 0.1 0.2 0.5 0.6 > > | 0.11 0.12 0.3 0.91 > > > ............................................................................ ................................................ > > .... > > # more rows with data > > > This table will first be created in an XML-like structure and will be > > displayed by the application as a table above. > > > I see an obvious pattern for using multidimensional arrays but not > > sure how to do this row-by row to populate the XML-tree .... > > > For example, if I have the file comp-1 and the first row of the table > > {ADA} input {ft 0.23} {fg 0.9} {df 0.45} {gh 0.33} > > > Do I have to read those all individual items into the array one by > > one? > > > set row(comp1,ADA,ft) 0.23 > > set row(comp1,DW,ft) 0.13 > > .... > > > and then write this into the XML file into appropriate tags? > > > Please advise. > > > Cheers! > > -Yil > > If you are using tcl8.5 (or tcl 8.4 with the dict extension) ... > > dict set row comp1 ADA ft 0.23 > dict set row comp1 DW ft 0.12 > > The neat part is, $row ends up as a list that can be manipulated by > the list commands or the dict command, dumped to a file, looped over, > it's really quite nice. > > -Sean "The Hypnotoad" Woods Thank you, Sean! I read the doc on dict but have not tried it yet. Seems to be another good option to populate tables with data. Thank you! |