understanding arrays, and their use



I am having a terrible time trying to comprehend arrays. I have a
simple task that I would like to do - read in a file, store the
information in an array, and be able to extract information from
specific fields in the array as I need the data. I have a pile of
books that all tell me the same thing about arrays - and I can't
understand a bit of it. Somebody - please take pity on me, and give me
a clue - Please!
Here's my file:

toola option1 string "path/to/resource"
toola option2 boolean nil
toola option3 string "itsok"
toola option4 boolean t
toola option5 boolean t
toola option6 string "startup option this is the tricky one"
toolb option1 string "path/to/another/resource"
toolb option2 boolean nil
toolb option3 boolean t
toolb option4 string "startup now"
....

There are several dozen lines in my real data, but it shouldn't make
much difference. There are extra spaces between the fields - I want to
treat more than one space the same as one space. Basically there are 4
fields. The fourth field can be a string enclosed in quotes with
either a file path, or multiple words separated by spaces. I need to
treat the 4th group as one field. I want to pull everything "toola"
out of the file, into an array. Later, I want to go through the array,
and set a variable named for each option (option1, option2, etc) to the
value in field 4.
I have tried lists, scanning, arrays, and I can't make sense of it. So
far, I have this code:

set tolookfor "toola"
set inFile [open $envFile r]
set envArray [split [read $inFile] "\n"]
foreach line $envArray {
foreach {first second third fourth } [split $line] { break }
if {[string compare $tolookfor $first] == 0 } {
set lookup($first) [list $second]
puts [array get lookup]
}
}
puts "item $tolookfor = $lookup($tolookfor)"

So this goes through, and scans the file, but what I am left with (aas
far as I can tell) is only the value from the last line scanned in
$lookup
HELP!! I need some answers, or a clue-by-four.

Grasshopper

.



Relevant Pages

  • Re: understanding arrays, and their use
    ... > specific fields in the array as I need the data. ... > toola option2 boolean nil ...
    (comp.lang.tcl)
  • Re: understanding arrays, and their use
    ... # specific fields in the array as I need the data. ... # toola option2 boolean nil ...
    (comp.lang.tcl)
  • Re: memory usage of Virtual function poiters
    ... It's not clear to me what your array is going to hold. ... given instance of Option2 can only hold one type. ... pointers to aBaseClass, and when retrieving a pointer from the array you'd ... and not a pointer for each virtual function. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: memory usage of Virtual function poiters
    ... >It is my understanding at this moment in time that with Option2 a VFPT ... But you cannot have arrays of mixed types even if they share a common ... You can have arrays of pointers to a common base of a polymorphic ... problem you are trying to solve with an array of 'mixed types' it is ...
    (alt.comp.lang.learn.c-cpp)