Tcl Array Looping Problem
From: Tommo (mark.thompson_at_talk21.com)
Date: 02/28/04
- Next message: David N. Welton: "Re: Slow Itcl class variable lookup"
- Previous message: William J Giddings: "Re: Ased"
- Next in thread: David McClamrock: "Re: Tcl Array Looping Problem"
- Reply: David McClamrock: "Re: Tcl Array Looping Problem"
- Reply: Bryan Oakley: "Re: Tcl Array Looping Problem"
- Reply: Michael Schlenker: "Re: Tcl Array Looping Problem"
- Reply: Ulrich Schöbel: "Re: Tcl Array Looping Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 ...
- Next message: David N. Welton: "Re: Slow Itcl class variable lookup"
- Previous message: William J Giddings: "Re: Ased"
- Next in thread: David McClamrock: "Re: Tcl Array Looping Problem"
- Reply: David McClamrock: "Re: Tcl Array Looping Problem"
- Reply: Bryan Oakley: "Re: Tcl Array Looping Problem"
- Reply: Michael Schlenker: "Re: Tcl Array Looping Problem"
- Reply: Ulrich Schöbel: "Re: Tcl Array Looping Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|