understanding arrays, and their use
- From: "Mr.B" <mark.r.bahlke@xxxxxxxxx>
- Date: 23 Jun 2005 09:03:44 -0700
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
.
- Follow-Ups:
- Re: understanding arrays, and their use
- From: Donald Arseneau
- Re: understanding arrays, and their use
- From: Roy Terry
- Re: understanding arrays, and their use
- From: Darren New
- Re: understanding arrays, and their use
- From: SM Ryan
- Re: understanding arrays, and their use
- Prev by Date: Re: vfs::zip problem
- Next by Date: Re: Cant access TCLLib when TCL is embedded in my application
- Previous by thread: Windows binaries for the Thread extension anywhere?
- Next by thread: Re: understanding arrays, and their use
- Index(es):
Relevant Pages
|