with requests about file open in tcl
many times i se no way to fix it and here on this
forum the talk about many times discussing it where
are those post so i can learn from that

here my script
can someone help me fixing the del option
thnx will
################ Set Db var`s ################
if {![file exists test.txt]} {
set fs [open test.txt a]
puts $fs "db script"
close $fs
}
################ Find args ################
bind pub - "!find" pub:search
proc pub:search {nick host hand channel args} {
set file "test.txt"
set found 0
set fs [open $file r]
while {![eof $fs]} {
gets $fs line
if {$line == $args} { set found 1 }
}
close $fs
if {$found} {
putquick "PRIVMSG $channel :$nick $args was found!"
} else {
putquick "PRIVMSG $channel :$nick $args was not found."
}
return 0
}
################ Add args ################
bind pub - "!add" pub:addin
proc pub:addin {nick host hand channel args} {
set file "test.txt"
set found 0
set fs [open $file r]
while {![eof $fs]} {
gets $fs line
if {$line == $args} { set found 1 }
}
close $fs
if {$found == "1"} {
putquick "PRIVMSG $channel :$args was found!"
} else { set fs [open $file a]
puts $fs "$args"
close $fs
putquick "PRIVMSG $channel :$args was add!"
}
return 0
}
################ Del args ################
bind pub - "!del" pub:del
proc pub:del {nick host hand channel args} {
set file "test.txt"
set found 0
set fs [open $file r]
while {![eof $fs]} {
gets $fs line
if {$line == $args} {
set found 1
set result $line }
}
close $fs
if {$found == "1"} {
putquick "PRIVMSG $channel :$args was found!"
} else { putquick "PRIVMSG $channel :$args was add!"
}
return 0
}
#the line to check if it is in my db file
#is done
#when i try to remove word3
#i get an error when i type !test 3 then not but nothing happend
#
bind pub - "!test pub:test
proc pub:test {nick host hand channel args} {
set file "test.txt"
set fp [open $file "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
set lines [lreplace $lines $args $args]
set fp [open $fp "w"]
puts $fp [join $lines "\n"]
close $fp
return 0
}
my file test.txt looks like this
word1
word2
word3
word4