egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

White lines in textfile after write

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
QQleQ
Voice


Joined: 20 Nov 2006
Posts: 14

PostPosted: Mon Nov 20, 2006 10:09 pm    Post subject: White lines in textfile after write Reply with quote

Hi there

All this script does is writing sentences or words to a textfile.. if its not in either deaud.txt or god.txt already.

Its working like a charm, however, i cant seem to get rid of some strange white lines (line breaks) in the text file. They keep comming back, even though i edit them out using vi.

Help apreciated.

Code:

bind pub n !deaud add:deaud

set deauds [split [read [set file [open "deaud.txt"]]] \n][close $file]
unset file
set god [split [read [set file [open "god.txt"]]] \n][close $file]
unset file

proc add:deaud {n u h c a} {

 global deauds
 global god

 if { [set b [split $a]] != "" } {
 if {[lsearch -exact $deauds [set b [split $a]]] == -1} {
 if {[lsearch -exact $god [set b [split $a]]] == -1} {
  lappend deauds $b
  putmsg $c "$b toegevoegd aan de deaudenlijst."
  save:deaud
 } {
  putmsg $c "$b staat al op de godenlijst."
 }
 } {
  putmsg $c "$b staat al op de deaudenlijst."
 }
 } {
    set qot_fd [open "deaud.txt" r]
    for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt } {
        gets $qot_fd qot_list($qot_cnt)
    }
    close $qot_fd
    set qot_cnt [expr $qot_cnt - 2]
    set qot_sel $qot_list([set qot_cur [rand [expr $qot_cnt + 1]]])
    putmsg $c "$qot_sel moet deaud. ([expr $qot_cur + 1] van [expr $qot_cnt + 1])"
 }
}

proc save:deaud {} {
 set a [open "deaud.txt" w]
 foreach bn $::deauds {
  puts $a $bn
 }
 close $a
}
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Mon Nov 20, 2006 11:32 pm    Post subject: Reply with quote

Code:

foreach bn $::deauds {
  puts $a [join $bn \n]
 }

Should do it..

I'd also put in a
Code:

if {$bn != ""} {
   puts $a [join $bn \n]
}

so its not saving blank lines..
Back to top
View user's profile Send private message
QQleQ
Voice


Joined: 20 Nov 2006
Posts: 14

PostPosted: Tue Nov 21, 2006 12:27 am    Post subject: Reply with quote

Hmz, for some reason that aint working

the text file now looks like this:

Code:

Zinloos Geweld
deadscripts
werkoverleg
maczut
loppie

Newlines

Het oude god-script

TiefusLineBreaks


Where the newly added lines are added from loppie (with this script) (the older lines where manually added with vi)

The script now looks like this:
Code:

bind pub - !deaud add:deaud

set deauds [split [read [set file [open "deaud.txt"]]] \n][close $file]
unset file
set god [split [read [set file [open "god.txt"]]] \n][close $file]
unset file

proc add:deaud {n u h c a} {

 global deauds
 global god

 if { [set b [split $a]] != "" } {
 if {[lsearch -exact $deauds [set b [split $a]]] == -1} {
 if {[lsearch -exact $god [set b [split $a]]] == -1} {
  lappend deauds $b
  putmsg $c "$b toegevoegd aan de deaudenlijst."
  save:deaud
 } {
  putmsg $c "$b staat al op de godenlijst."
 }
 } {
  putmsg $c "$b staat al op de deaudenlijst."
 }
 } {
    set qot_fd [open "deaud.txt" r]
    for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt } {
        gets $qot_fd qot_list($qot_cnt)
    }
    close $qot_fd
    set qot_cnt [expr $qot_cnt - 2]
    set qot_sel $qot_list([set qot_cur [rand [expr $qot_cnt + 1]]])
    putmsg $c "$qot_sel moet deaud. ([expr $qot_cur + 1] van [expr $qot_cnt + 1])"
 }
}

proc save:deaud {} {

set a [open "deaud.txt" w]

foreach line [split $::deauds \n] {
   if {$line != "" && $line != "\n"} {
    puts $a [join $line \n]
   }
}


 close $a
}


What am i doing wrong?
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Tue Nov 21, 2006 3:02 pm    Post subject: Reply with quote

You split the line twice, once again with the foreach..
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Thu Nov 23, 2006 3:41 pm    Post subject: Reply with quote

wouldnt just
Code:
proc save:deaud {} {
   set a [open "deaud.txt" w]
      puts -nonewline $a [join $::deauds \n]
   close $a
}

do the trick?

PS: I would move "[close $file]" to the next line and remove [] braces. close is not suposed to return anything but an empty string, but I still wouldn't add a probably empty string to something I want to parse as a consident list.
_________________
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber