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.
Old posts that have not been replied to for several years.
MrAnderson
Voice
Posts: 9 Joined: Tue Aug 24, 2004 9:34 am
Location: Portugal
Post
by MrAnderson » Mon Jan 03, 2005 1:17 pm
Hello. i was tying to put a egg reading a file, and put the file in the channel or private windows, but the egg only read's the fisrt line, i try lot's of way's, follow wat is in the egg faq called " Basic File Operations" but i can't doint.
This is the code:
Code: Select all
bind msg - !partidas msg:partidas
proc msg:partidas {nick uhost handle arg} {
if {![file exists partidas.txt] } {
putserv "PRIVMSG $nick : ERROR: File dont exist"}
set jogos [open partidas.txt r]
set ptmsg [read -nonewline $jogos]
#set lines [split $jogos "\n"]
#set numlines [llength $lines]
putserv "PRIVMSG $nick :Last games:"
putserv "PRIVMSG $nick :$ptmsg"
putserv "PRIVMSG $nick :To delete make !reset"
close $jogos
}
Can anywane help me? I want make the egg read all the file and not only the fisrt line.
tks
P.S. Sorry for my bad english.
Last edited by
MrAnderson on Mon Jan 03, 2005 6:00 pm, edited 1 time in total.
demond
Revered One
Posts: 3073 Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:
Post
by demond » Mon Jan 03, 2005 2:13 pm
you are trying to read a file that doesn't exist
MrAnderson
Voice
Posts: 9 Joined: Tue Aug 24, 2004 9:34 am
Location: Portugal
Post
by MrAnderson » Mon Jan 03, 2005 2:44 pm
no, there is a } before the rest.
i am trying to read a file that exist, and work's, but only read the fist line, and not all =\
And i don't know do it =\
Bruno, vOdKa^Dj @ PTnet
demond
Revered One
Posts: 3073 Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:
Post
by demond » Mon Jan 03, 2005 2:56 pm
try:
Code: Select all
set f [open file.txt]
while {![eof $f]} {lappend lines [gets $f]}
close $f
MrAnderson
Voice
Posts: 9 Joined: Tue Aug 24, 2004 9:34 am
Location: Portugal
Post
by MrAnderson » Mon Jan 03, 2005 3:10 pm
sorry.. but can you explain better?
Is to resume for me, a try that, but i think that im doing that not in the right way.
Bruno, vOdKa^Dj @ PTnet
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Mon Jan 03, 2005 3:10 pm
demond wrote: try:
Code: Select all
set f [open file.txt]
while {![eof $f]} {lappend lines [gets $f]}
close $f
Using eof like that will give you a empty element at the end of the list if the last line ends with a newline.
Try
Code: Select all
set f [open file.txt]
while {[gets $f line]>-1} {
#output $line
}
close $f
or
Code: Select all
set f [open file.txt]
foreach line [split [read -nonewline $f] \n] {
#output $line
}
close $f
Have you ever read "The Manual"?
MrAnderson
Voice
Posts: 9 Joined: Tue Aug 24, 2004 9:34 am
Location: Portugal
Post
by MrAnderson » Mon Jan 03, 2005 3:29 pm
try and try and notting =\
This is the code rewrithem:
Code: Select all
bind pub - !partidas pub:partidas
proc pub:partidas {nick uhost handle chan arg} {
set fname "partidas.txt"
if {![file exists $fname] } { putserv "PRIVMSG $nick :Sem novas partidas"}
foreach line [split [read -nonewline $fname] \n] {
putserv "PRIVMSG $nick :Ultimas partidas reportadas:"
putserv "PRIVMSG $nick :$line"
putserv "PRIVMSG $nick :Para as eleminar faça !reset"
}
close $fname
}
And this is the error that happens:
[19:25] Tcl error [pub:partidas]: can not find channel named "partidas.txt"
tks for the help
Bruno, vOdKa^Dj @ PTnet
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Mon Jan 03, 2005 3:34 pm
1: you continue even if the file doesn't exist.
2: you never open the file
3: the start/end messages are inside the loop (which I doubt is what you want)
Last edited by
user on Mon Jan 03, 2005 3:35 pm, edited 1 time in total.
Have you ever read "The Manual"?
demond
Revered One
Posts: 3073 Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:
Post
by demond » Mon Jan 03, 2005 3:34 pm
you didn't open the file
MrAnderson
Voice
Posts: 9 Joined: Tue Aug 24, 2004 9:34 am
Location: Portugal
Post
by MrAnderson » Mon Jan 03, 2005 5:46 pm
weee... tks ppl for helping me. now it work's at 100%
final code:
Code: Select all
bind pub - !partidas pub:partidas
proc pub:partidas {nick uhost handle chan arg} {
if {![file exists partidas.txt] } { putserv "PRIVMSG $nick :Sem novas partidas"
} else {
set f [open partidas.txt]
putserv "PRIVMSG $nick :Ultimas partidas reportadas:"
while {[gets $f line]>-1} {
putserv "PRIVMSG $nick :$line"
}
putserv "PRIVMSG $nick :Para as eleminar faça !reset"
close $f
}
}
But I have only one last question, went we put
close $f $f is [
open (..) don't is better to put the name of the file?
like
close partidas.txt or the final resut will be the same?
and one more time.. tks [[]]
Bruno, vOdKa^Dj @ PTnet
the_crow
Halfop
Posts: 42 Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal
Post
by the_crow » Mon Jan 03, 2005 6:03 pm
what you can do:
Code: Select all
set ficheiro "partidas.txt"
bind pub - !partidas pub:partidas
proc pub:partidas {nick uhost handle chan arg} {
global ficheiro
if {![file exists $ficheiro] } { putserv "PRIVMSG $nick :Sem novas partidas"
} else {
set f [open $ficheiro "r"]
putserv "PRIVMSG $nick :Ultimas partidas reportadas:"
while {[gets $f line]>-1} {
putserv "PRIVMSG $nick :$line"
}
putserv "PRIVMSG $nick :Para as eleminar faça !reset"
close $f
}
}
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Mon Jan 03, 2005 7:04 pm
vodkaPT wrote: But I have only one last question, went we put close $f $f is [open (..) don't is better to put the name of the file?
like close partidas.txt or the final resut will be the same?
close expects the name of a file channel, not the name of a file. Check the
manual and read up on the
syntax ...you'll see why the contents of 'f' is not '[open file.txt]', but what
open returned (because of
command substitution )
Have you ever read "The Manual"?
MrAnderson
Voice
Posts: 9 Joined: Tue Aug 24, 2004 9:34 am
Location: Portugal
Post
by MrAnderson » Thu Jan 06, 2005 9:30 am
user, my eggdrop is givem that error of "no channel call file.dat " and now i cam understeend why.. tks [[]]
Bruno, vOdKa^Dj @ PTnet