I just wandering, what is mean the part of this code, especially seek 0 end command,
seek $a 0 end
seek $c 0 end
seek $e 0 end
seek $g 0 end
catch {close $a}
catch {close $c}
catch {close $e}
catch {close $g}
coz i have problem with too many open files when i load this tcl, so how about if i change a little different at above part code and change them like this:
seek $a 0 end
catch {close $a}
}
seek $c 0 end
catch {close $c}
}
etc...
so...problem too many open files will be avoid. Hmm...i wander, would it be the same or will give a different meaning from the old code??
thx, i just want to know how they work, so maybe i'll understand (at least i try to understand) to fix my current problem about this.
if I remember correctly you opens all the file for reading then if none of it matches you write to the last file.... correct?
if that was the case maybe you should try opening just one file at the time.... open 1--->close 1 open 2--->close 2 ....etc
this probably means that you'll have to rewrite parts of your code..but maybe it's worth a shot
[01:57] can't read "text": no such variable
while executing
"string match -nocase "*$text*" $d"
(file "scripts/test.tcl" line 1)
(file "mybot" line 1)
[01:57] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
set a [open $files(1) r+]
set b [read $a]
if {[string match -nocase "*$text*" $b]} {
return 0
}
seek $a 0 end
catch {close $a}
set c [open $files(2) r+]
set d [read $c]
if {[string match -nocase "*$text*" $d]} {
return 0
}
etc...
seek $g 0 end
catch {close $g}
puts $a $text
but when i test add something to my egg, it was killed, no error just seems not enough memory or ram. so...how to make they work well without spend to many memory of my shell?
thx
set a [open $files(1) r+]
set b [read $a]
if {[string match -nocase "*$text*" $b]} {
return 0
}
seek $a 0 end
catch {close $a}
Hmm... where's the sense in reading a file, jumping to the end (where you already are when reading the file to the end ) and then closing the file? ...and you return before closing the file if it matches -> open file descriptor
well....actually i dont have any idea, i already try to make variations of that code, but the result is error and this is my last alternative variation and it seems dont have any error (my bot can be loaded) but if i test and add something to it, it killed (i think it because lack of memory of my shell) and now completely confuse and really need help or suggest from anyone, i dont pretty much smart about tcl, so can you make more specify what should i do? thx
seek jumps to the specified file position...
seek $fa 0 end -> jump to 0 bytes after the end of the file... that's where you are, when reading a file from the start to the end.
a 'catch { close $fd }' closes file descriptor $fd and returns no error, even if the file is closed already
This appends $text to the first opened file, if $text is in none of the files
set fa [open $files(1) r+]
set txt [read $fa]
### here you're at the end of $files(1) ...
if {[string match -nocase "*$text*" $txt]} {
### remember to close $file(1) if $text is there:
catch { close $fa }
return 0
}
set fb [open $files(2) r]
set txt [read $fb]
catch { close $fb }
if {[string match -nocase "*$text*" $txt]} {
### remember to close $file(1) if $text is there:
catch { close $fa }
return 0
}
... snip ....
catch { close $fx }
if {[string match -nocase "*$text*" $txt]} {
catch { close $fa }
return 0
}
puts $fa $text
catch { close $fa }
If you want to replace the content of $file(1) insert a 'seek $fa 0 start' before the 'puts $fa $text'
set a [open $files(1) r+]
set b [read $a]
if {[string match -nocase "*$text*" $b]} {
catch {close $a}
return 0
}
set c [open $files(2) r+]
set d [read $c]
if {[string match -nocase "*$text*" $d]} {
catch {close $c}
return 0
}
...etc....
puts $a $text
catch {close $a}
}
putlog "new.tcl loaded"
but still my eggs getting killed with quit message (Client closed connection), and closed by remote section when i'm using telnet if i test by adding $text that already on the file (i want to test if the code works to denied a text that already on file), but the result is always killed....
Why?