Tcl Array Looping Problem

From: Tommo (mark.thompson_at_talk21.com)
Date: 02/28/04


Date: 28 Feb 2004 01:11:25 -0800

Hello All,
         Can anyone point me in the right direction, I am a newbie to
Tcl so I am trying to apply my Perl knowledge to this script.
Basically I have built up 2 Arrays (AS1 & AS2), I want to iterate over
one array checking each entry against the second array, if the entry
exists in the 2nd Array then I do nothing, if it does not exists I
simply ADD it to the 1st array.
      What I have done does not seem to work, is there a problem and
what is the answer or is their a better way ...

Arrays
--------
set AS1(0) "A"
set AS1(1) "B"
set AS1(2) "C"

set AS2(0) "A"
set AS2(1) "B"

Code
------
foreach element $AS1 {
for {set i 0} {$i >= $AS2size} {incr i +1} {
if {[info exists $AS2($i)]} {
                             puts "$info EXISTS in Array 1\n"
                            } else {
                                   set AS2New [expr $AS2size+1]
                                   set AS2($AS2New) $info
                                   }
                                           }
                     }

Expected Results
-------------------

Array AS2 should contain A, B & C

thanks, Mark ...



Relevant Pages

  • Re: This question seems simpler than it actually is...
    ... find a lot of logic designers forget what HDL stands for... ... For the exercise I went ahead and did this with a 6 element array. ... type invect is array of entry; ... case mystate is ...
    (comp.lang.vhdl)
  • Re: A critique of test-first...
    ... > silly to give a coding test to people of our level; ... Each message will have the cummulative probability. ... To find a random message get a number from randand find the entry ... Use a sparse/dense array of chars. ...
    (comp.programming)
  • Re: A critique of test-first...
    ... > silly to give a coding test to people of our level; ... Each message will have the cummulative probability. ... To find a random message get a number from randand find the entry ... Use a sparse/dense array of chars. ...
    (comp.programming)
  • Re: Removing entry from @rray
    ... For some time I have been using two different method for removing an entry ... and places each line into the array. ... Redefining the @array element inside to loop ...
    (comp.lang.perl.misc)
  • Re: Framework 2.0 array redim unsatisfactory performance
    ... Not a surprise, most likely it is implemented as single-linked ... Implements the System.Collections.Generic.IListinterface using an array ... How are you determining "at least 5 additional bytes for each entry"? ... | The reason why I test Array is because I need a dynamic data structure ...
    (microsoft.public.dotnet.languages.vb)