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.

Weird problem with a txt-file

Help for those learning Tcl or writing their own scripts.
Post Reply
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Weird problem with a txt-file

Post by darton »

Hello!
I made this script:

Code: Select all

bind pub - !modlog atmlog
proc atmlog {nick uhost hand chan arg} {
  set fd [open $::atmfile r]
      while {![eof $fd]} {
         lappend list [gets $fd]
         set lines [split [read $fd] \n]
      }   
      close $fd           
       foreach x $lines {
         putquick "NOTICE $nick :$x"
       }        
    return 1
}
I can't see a mistake in it and an error message does not occur. Actually this script should read a textfile and give all lines with a notice to a user. So, where is the mistake?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

Hint:

Code: Select all

      while {![eof $fd]} {
         lappend list [gets $fd]
      }
and

Code: Select all

         set lines [split [read $fd] \n]
are equivalent (except for saving into 2 diffrent vars).
btw. $lines will be an empty string if *edit* there is only one line */edit*.

Advise: why not simply

Code: Select all

      while {![eof $fd]} {
         putquick "NOTICE $nick :[gets $fd]"
      }
Last edited by De Kus on Wed Jul 19, 2006 3:56 am, edited 1 time in total.
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...
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

Thank you. It works perfectly.
Post Reply