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.
e
ellis
Post
by ellis » Fri Apr 25, 2003 4:22 pm
how du i write things to a file ?...
i need to make a log script and that preety mutch the only thing i need to know =)
Papillon
Owner
Posts: 724 Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no
Post
by Papillon » Fri Apr 25, 2003 7:07 pm
Code: Select all
##open the file for writing
set fid [open $fid]
##set the line to put into the file
set line "This line into the file"
##put the line into the file
puts $fid $line
##close the file
catch {close $fid}
Read some tutorial or the TCL manual
http://tcl.activestate.com/man/tcl8.4/T ... ntents.htm to get more info about how to open the file for reading/appending... etc
Elen sila lúmenn' omentielvo
e
ellis
Post
by ellis » Sat Apr 26, 2003 3:31 pm
thx alot mate
e
ellis
Post
by ellis » Sat Apr 26, 2003 3:47 pm
humm... maby its me that realy stupid and missed somthing u just wrote or u missed out the part were i need to typ in what file i whant to open =P
e
ellis
Post
by ellis » Sat Apr 26, 2003 4:10 pm
bind PUBM - * pubm:logev
proc pubm:logev ( nick uhost handle channel text) {
set line1 $line2
set line2 $line3
set line3 $line4
set line4 "$nick: $text"
set fid log.txt [open $fid]
set line $line4
puts $fid $line
catch {close $fid}
}
whats wrong ??... this is quite of a guess so dont flame me if i have done a realy "n00b n00b" misstake
MC_8
Voice
Posts: 36 Joined: Sat Apr 26, 2003 5:04 pm
Location: Dallas, Texas
Contact:
Post
by MC_8 » Sat Apr 26, 2003 6:11 pm
Code: Select all
bind pubm - * proc_name
proc proc_name {nick uhost handle channel arg} {
if {![file exists log_file]} {close [open log_file w]}
set io [open log_file a]
puts $io "<$nick@$channel> $arg"
close $io
}
e
ellis
Post
by ellis » Sun Apr 27, 2003 2:35 am
that works exelent. but how du i make it so that it cuts of the first line if there is more then a sertan number of lines allready, in the log
MC_8
Voice
Posts: 36 Joined: Sat Apr 26, 2003 5:04 pm
Location: Dallas, Texas
Contact:
Post
by MC_8 » Sun Apr 27, 2003 5:36 am
You can open the file for reading and load it all into memory then use llength to get whatever you need.
Code: Select all
if {![file exists log_file]} {close [open log_file w]}
set io [open log_file r]
set list ""
while {![eof $io]} {
gets $io line
if {[string trim $line] == ""} {continue}
lappend list $line
}
close $io
lappend list "<$nick@$channel> $arg"
set st [expr [llength $list]-50]; #assuming you want only the last 50.
set list [lrange $list $st end]
set io [open log_file w]
foreach line $list {
puts $io $line
}
close $io