Re: Having problem with SPLIT
- From: "Earl Grieda" <egriedaNOT@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 30 Jun 2005 19:36:40 GMT
"Bryan Oakley" <oakley@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:obXwe.1277$U61.1189@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Earl Grieda wrote:
> > "Ralf Fassel" <ralfixx@xxxxxx> wrote in message
> > news:yga1x6j99zj.fsf@xxxxxxxxxxxxxxxxxxxxxxxxxx
> >
> >>* "Earl Grieda" <egriedaNOT@xxxxxxxxxxxxxxxxxxx>
> >>| if {$::DEBUG} {puts "FIRST0: $orgLine"}
> >>
> >>Please show how 'orgLine' is set.
> >>Is it
> >> set orgLine "\tHeader with a tab"
> >
> >
> > orgline is set by reading a file (the email file).
> > set orgLine [gets $inputFileID]
> > and the line in the email file is
> > \tHeader with a tab ;# \t is 2 chars
> >
> > I then do
> > set line [split [regsub -all { +} $orgLine " "]]
> > to insure there is only one space between each word and make it
> > a list so I can use list operations on it. The idea being that
> > the first item in the list is a flag and, depending on the flag,
> > some action is done with the rest of the line.
>
> Ok, so you're reading a string and you're trying to treat it as a
> list of space-separated words. Only, it's not really a list of space
> separated words, it's really just a string with no guarantee of the
> format (other than the first "word" is really a flag).
>
I guess I misunderstand the "split" documentation, which says "split - Split
a string into a proper Tcl list". Why is, after the split, the line is "not
really a list of space separated words, it's really just a string"?
http://www.tcl.tk/man/tcl8.4/TclCmd/split.htm
> That seems like a recipe for disaster.
No, it works great. This has been running for years and keeps getting
enhanced to do more. A few years ago I used to have problems with errant
emails, before I added the "split" to [split $line]. Then, I was treating a
string as a list, with the occasional resultant crash.
The problem started when I thought it would be nice to have HTML and/or tabs
in a header, so I tested it to see if it works. But, "split" changes the
word "\tHeader" to {\tHeader}, which started this thread. The "split"
documentation says:
"Extract the list words from a string that is not a well-formed list:
split "Example with {unbalanced brace character"
=> Example with \{unbalanced brace character
"
It doesn't mention doing anything special with chars that could be
interpreted as control characters, such as \t. I did try using \\tHeader,
but that didn't make any differance.
>
> Since you're only interested in the first word at this point, how about
> just pulling out the flag and leaving the rest of the data alone?
>
> # put in whatever pattern fits your actual data
> regexp {^([a-zA-Z0-9_]+)} $orgLine -- flag
>
> Is there a specific reason you're converting a string to a list, other
> than to make it easy to pick out the first word? It looks like the crux
> of your problem is that program A is changing the nature of the data
> before passing it to B. Thus, B gets a string representation of a list
> representation of the original string, which is not the same as the
> original string.
>
This is a communications protocol. Currently I am using email as the
transport mechinism, but am slowly moving to sockets. The first word
determines how the remainder of the line is treated. Differant flags result
in differant operations. In this case the header flag states that the rest
of the line is a header.
.
- Follow-Ups:
- Re: Having problem with SPLIT
- From: Bryan Oakley
- Re: Having problem with SPLIT
- References:
- Having problem with SPLIT
- From: Earl Grieda
- Re: Having problem with SPLIT
- From: Bryan Oakley
- Re: Having problem with SPLIT
- From: Earl Grieda
- Re: Having problem with SPLIT
- From: Ralf Fassel
- Re: Having problem with SPLIT
- From: Earl Grieda
- Re: Having problem with SPLIT
- From: Bryan Oakley
- Having problem with SPLIT
- Prev by Date: Re: Having problem with SPLIT
- Next by Date: Re: Having problem with SPLIT
- Previous by thread: Re: Having problem with SPLIT
- Next by thread: Re: Having problem with SPLIT
- Index(es):
Relevant Pages
|