eof is, in one sense, a command:http://purl.org/tcl/home/man/tcl8.4/TclCmd/eof.htmand, in another sense, an acronym for End Of File.
Programmers can use eof to determine whether the channel has reached the end of input.Note that it fires only after the last successful gets, so testing for a -1 return value on gets may be a better idea, and avoid eof's FMM [1] by coding:
while {[gets $fp line]>=0} {...}instead of while {![eof $fp]} {
gets $fp line
if [eof $fp] break ;# otherwise loops one time too many
...
} ;# RSHmmm... the only thing I find eof good for is as a condition which should trigger closing a socket.That is, if you are trying to read a non-blocking socket and you hit eof, you KNOW that it's time to close the socket.-PSE
Can anyone indicate whether there are certain types of channels (pipe, socket, etc.) where eof doesn't do what one might at first blush expect?JMN 2003-07-15 This isn't directly referring to the eof command - but is an EOF issue that I wasn't expecting so here looks as good a place as any to mention it.Using the Memchan package, I was trying to fcopy from a memchan to a file roughly like so:
package require Tcl
package require Memchan
set fd [open "/tmp/output.txt" "w"]
set m [memchan]
puts $m "someStringData"
seek $m 0 start
fcopy $m $fd -command CopyFinished
proc CopyFinished args { puts $args }
puts "Application has completed"This performed the copy to file just fine, but the CopyFinished proc never got called. To fix this, I called fconfigure $m -eofchar {}before the puts someStringData line andfconfigure $m -eofchar \x1abefore the fcopy line. Then I changed the puts line to:
puts $m "someStringData\x1a"This seems like a bit of hoop-jumping to get the expected fcopy behaviour.. am I missing something simple?
Tcl syntax help - Arts and Crafts of Tcl-Tk Programming[ Category Command | Category Channel | Category Introspection ]