Re: understanding arrays, and their use



"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.
.



Relevant Pages

  • Re: Dont understand this syntax -
    ... > concept of a Unix OS for the Mac or I might have had an additional 15 ... But anyway - I don't see the reference to awk as being all that important. ... "Splits on whitespace " is pretty ...
    (comp.lang.perl.misc)
  • Re: understanding arrays, and their use
    ... the input file is rather badly behaved. ... then proceed to feed the rest of the file into an array for further ... I will look into the parray function; ... The other thing I see as a problem is the problem of whitespace. ...
    (comp.lang.tcl)