| scdtl@yahoo.com 2005-02-28, 8:58 am |
| Kevin -
I'm essentially a novice at Tcl, so this reply should be read
accordingly. I encountered what may be a similar situation while trying
the example of Figure 16.10 in the Ousterhout text. It presents a
listbox of a large number of color names, read from a file called
'rgb.txt'.
What I found was a glitch in the listed code, in that the file, at
least on my Linux box, contained a header line, which was clearly not
accounted for by the code. The Ousterhout code is:
listbox .colors
pack .colors
set f [open /usr/lib/X11/rgb.txt]
while {[gets $f line] >= 0} {
.colors insert end [lrange $line 3 end]
}
close $f
bind .colors <Double-Button-1> {
.colors configure -background [selection get]
}
The solution in this case was remarkably simple - just add a line
gets $f line
before the 'while', to bypass the offending header line. This solution
assumes that an undesired header line is always present, and always at
the top of the file.
Another solution to this problem might be to use 'grep' to identify the
offending line and drop it out, using a pipe scheme to filter the file
through the grep.
-Lance
|