This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Write/reading file question

Old posts that have not been replied to for several years.
Locked
I
Ixje

Post by Ixje »

k i got 2 questions.
1)

Code: Select all

bind pub - !addREQ pub:addREQ

proc pub:addREQ {nick uhost hand chan REQ} {
global REQdir
if {$REQ != ""} {
set fs [open REQ.db w]
puts $fs "$REQ"
puthelp "NOTICE $nick : $REQ added to request list"
close $fs
} else { 
puthelp "NOTICE $nick :Usage: !addREQ <requested file>" 
} 
} 
This part keeps overwriting the added request instead of adding it to the file/list.
f.e. if i type !addREQ test and !addREQ test2 the REQ.db should have both lines in it and currently it only has the last one. :

2) For the reading part i have this

Code: Select all

bind pub = !viewREQ pub:viewREQ

proc pub:viewREQ {nick uhost hand chan arg } {
set fs [open REQ.db r]
set info [read $fs]
putserv "NOTICE $nick : $fs" 
close $fs
}
But if i type !viewREQ i get this -> TCL error [pub:viewREQ]: channel "file10" wasn't opened for reading and typing !viewREQ again makes it file11 , file12 etc etc.
I don't know where the hell he gets it from but i just wan't to see the list of requests from the REQ.db

Thnx for all you help

-Da Newbie Out

<font size=-1>[ This Message was edited by: Ixje on 2002-01-10 10:52 ]</font>
M
Mata Hari

Post by Mata Hari »

1st:
set fs [open "REQ.db" a]
(a will append, w will truncate and overwrite)

the second is a weird error wich shouldn't happen afaik, you can try to put REQ.db in quotes ("REQ.db") and try r+ instead of r

it could be a tcl problem (wich version are you using?)

btw.
putserv "NOTICE $nick : $fs" isn't right, it should be $info instead of $fs, but also, $info will have eol chars in it when using read, use something like

Code: Select all

foreach line [split $info "n"] {
  putserv "NOTICE $nick : $line"
}
hope this helps atleast a bit


I
Ixje

Post by Ixje »

Thnx it works now :mad:
(this is my first script so it's still kinda hard ;P)
Locked