Behavior of 'split' command
Quote:
>> Hi:
>> I am more than a little confused about the output of the split command when
>> reading in lines from a text file. What I am attempting to do is read in
>> lines of text from a file and make each line entry a separate list in the
>> list such that the result looks like this:
>> theList { {Joe:Doe:Engineer} {Jane:Doe:Scientist} }. The format of the file
>> containg the data to be read is:
>> Joe:Doe:Engineer
>> Jane:Doe:Scientist
>> Each entry is ended by a newline.
>> Assume the file was opened sucessfully.
>> Here is my code for adding these list elements:
>> lappend theList [split [read $theListFile] \n]
>> What I expected was { {Joe:Doe:Engineer}
>> {Jane:Doe:Scientist} }
>> What was returned was { Joe: Doe Engineer
>> Jane:Doe:Scientist }
>> Reading the man pages and the leading Tcl books I have come to the
>> understanding that my code should have produced what I expected. Can
>> someone enlighten me about how the split command should work and what I am
>> missing to produce my expected output?
>It sounds like your confused about the difference between strings and
>lists.
>For instance
> set aString {{Joe:Doe:Engineer} {Jane:Doe:Scientist}}
> lappend aList {Joe:Doe:Engineer} {Jane:Doe:Scientist}
> puts $aString ;#==> {Joe:Doe:Engineer} {Jane:Doe:Scientist}
> puts $aList ;#==> Joe:Doe:Engineer Jane:Doe:Scientist
>Perhaps someone else can follow up with more detail...
.
.
.
Summary: I expect that Mr. Wilson will eventually decide he wants
simply
set theList [split [read $theListFile] \n]
Glenn's $aString can be interpreted as a list; as a list, it's
indistinguishable from $aList. Try
puts [lindex $aString 0]
puts [lindex $aList 0]
Is it really true that "What was returned was
{ Joe: Doe Engineer Jane:Doe:Scientist }
"? Does the external file truly have a line
Joe: Doe Engineer
rather than
Joe:Doe:Engineer
?
--
Business: http://www.Phaseit.net