Re: understanding arrays, and their use
- From: SM Ryan <wyrmwif@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 23 Jun 2005 22:11:02 -0000
"Mr.B" <mark.r.bahlke@xxxxxxxxx> wrote:
# Unfortunately, the input file is rather badly behaved. I can't count
# on the first line being the first line. It's just the first line in my
# example, which reproduces the structure of my input file, but not the
# specifics of line order. Having said all that, I still wouldn't know
# how to get the first line of the file out to use that split on, and
# then proceed to feed the rest of the file into an array for further
You can also use regexp do many types of parsing. Perhaps instead
foreach {first second third fourth} $line break
you might be able to do
if {[regexp regexp {^(\S+)\s+(\S+)\s+(\S+)\s+(?:")?([^"]+)(?:")?$} \
$line - first second third fourth]
} continue
# The other thing I see as a problem is the problem of whitespace. I'm
# used to perl, and awk and so forth treating all whitespace as the same.
# Here in TCL-land, you have to keep track even of things you can't see
# (whitespace). That's frustrating too. Isn't there some sort of switch
# like "wish -treatAllSpacesTheSame"? That sure would be nice :)
You can reduce all whitespace sequences in a string to one blank character with
regsub -all {\s+} $line { }
--
SM Ryan http://www.rawbw.com/~wyrmwif/
You hate people.
But I love gatherings. Isn't it ironic.
.
- References:
- Re: understanding arrays, and their use
- From: Mr.B
- Re: understanding arrays, and their use
- Prev by Date: Re: Concating strings
- Next by Date: Re: Concating strings
- Previous by thread: Re: understanding arrays, and their use
- Next by thread: Re: understanding arrays, and their use
- Index(es):
Relevant Pages
|