Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Curly bracket occur when retrieve data from a text file

Status
Not open for further replies.

jloh81

Programmer
Jun 15, 2010
16
US
My code is as below

set devicelist ""
set readdevice [open "device.txt" r]
while {[gets $readdevice linenew] != -1} {
lappend devicelist $linenew
}
puts $devicelist

and the result is

device1 device2 device3 { device4 } { device5 } { device5 }

Question 1
why my result sometime with curly bracket and sometime is not with the curly bracket?

Please advice
 
Hi

That has nothing to do with reading from file. Your devicelist is a list, the list separator is the space, so list items containing space are quoted.
Code:
[blue]%[/blue] set devicelist ""
[blue]%[/blue] lappend devicelist "one"
one
[blue]%[/blue] lappend devicelist "two three"
one {two three}
[blue]%[/blue] lappend devicelist "four"
one {two three} four
[blue]%[/blue] lappend devicelist "five six seven"
one {two three} four {five six seven}
If you want to make your list a simple variable :
[ul]
[li][tt]join $devicelist[/tt] - all a single line[/li]
[li][tt]join $devicelist "\n"[/tt] - with line breaks as in the file[/li]
[/ul]


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top