set file templist
set found 0
set fs [open $file r]
while {![eof $fs]} {
gets $fs line
if {$line == $nick} { set found 1 }
}
close $fs
if {$found} {
puthelp "PRIVMSG $chan : was found!"
} else {
puthelp "PRIVMSG $chan : was not found."
}
<font size=-1>[ This Message was edited by: [Nero] on 2002-06-04 12:16 ]</font>
yes. this is true for just about every language. eof is a function of a read statement - it gets set as a result of a failed read due to falling off the end of the file. opening a file never checks whats in it, or how long it is. It just opens the file descriptor and points to the first byte of the file (if it exists or not). It only discovers if it exists once you try to read it.
Beside the counting offset of one line, the code "while {![eof $fp]}" doesn't produce any errors afaik. But it should be clear that one extra empty line is processed by the code following the [gets]. This may be undesired behaviour.
One can argue that the "while {![eof $fp]}" at least makes explicit what the intention of the code is.
To make the intention explicit one could also throw in a "# read until EOF" line.