Hy all! This is my first post here, I just downloaded eggdrop and I'm a newbie to TCL scripting. I scripted in mIRC scripting before but TCL brings new and harder topics to understand. Well what I need (and could not find out) is how can I overwrite a line in a file without the need of reading the previous lines or using a temporary file. Here is my code that I have now:
Code: Select all
bind part - * data_seen
proc data_seen {nick uhost hand chan text} {
set file1 [open "DSotM/Temp/Seen.txt" r]
set file2 [open "DSotM/Temp/Tmp/Seen.txt" w]
set host [lindex [split $uhost @] 1]
set date [clock format [clock seconds] -format "%D"]
set time [clock format [clock seconds] -format "%T"]
set contor 0
while {[gets $file1 line] >= 0 && $contor == 0} {
if {[lindex $line 0] == $nick} {
puts $file2 "$line"
}
}
puts $file2 "$nick $host $date $time"
close $file1
close $file2
file copy -force "DSotM/Temp/Tmp/Seen.txt" "DSotM/Temp/Seen.txt"
file delete "DSotM/Temp/Tmp/Seen.txt"
}
Now this script is opening the original file, $file1, read lines from it and if the nick that parted the channel it's not the nick in the file, it writes that line to a temporary file. Then at the end it appends the nick, host, date and time variables to that temp file and then it overwrites the original file. Now this works for small files, but with files larger than 1000 nicks (and that is very possible for a crowded channel) this proccess of reading and writing takes veeeeery much time. How can insert that $nick $host $date $time at a defined line in the original file, so I won't have 2 lines with the same nick on them?
Thank you in advance, Christmas_.
LE: Sorry for that code formatting, how do I use that code tags?