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.

Delete a line

Help for those learning Tcl or writing their own scripts.
Post Reply
l
l.kleijn
Voice
Posts: 33
Joined: Sun May 18, 2014 10:02 am

Delete a line

Post by l.kleijn »

Code: Select all

proc msg:calculate {nick host hand arg} {
  global botnick opchan
  set fname "remember.txt"
  set fp [open $fname "r"]
  set data [read -nonewline $fp]
  close $fp
  set lines [split $data "\n"]
  set linetodelete 0
  set lines [lreplace $lines $linetodelete $linetodelete]
  set fp [open $fp "w"]
  puts $fp [join $lines "\n"]
  close $fp
  putserv "PRIVMSG Fujin :Done."
}
I got this from this site but it won't work for me, could someone help me.
To remove a line from a txt file.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Hello,
Assuming you'd like to remove the top-line of the file named "remember.txt", the main problem is at line 10, where you open the file for write-access, but mistakenly use $fp instead of $fname for filename:

Code: Select all

set fp [open $fp "w"]
should be changed into

Code: Select all

set fp [open $fname "w"]
On a side-note, there's no point in mapping global varialbes botnick or opchan into this proc, as it never uses either of those variables.
NML_375
l
l.kleijn
Voice
Posts: 33
Joined: Sun May 18, 2014 10:02 am

Post by l.kleijn »

Code: Select all

proc msg:calculate {nick host hand arg} {
  global botnick opchan
  set fname "remember.txt"
  set fp [open $fname "r"]
  set data [read -nonewline $fp]
  close $fp
  set lines [split $data "\n"]
  set linetodelete [expr {[llength $lines] -1}] 
  set fp [open $fname "w"]
  puts $fp [join $lines "\n"]
  close $fp
  putserv "PRIVMSG Fujin :Done."
}
It doesn't work i don't know anymore.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Well, it seems that you've done additional modifications since the original post; now you've removed the "lreplace" command, which is actually used to remove an element (line from the file) from the list (of lines), before writing it back to the file.
NML_375
l
l.kleijn
Voice
Posts: 33
Joined: Sun May 18, 2014 10:02 am

Post by l.kleijn »

But even with the quote of the original post, change the file you sayd, it don't work
w
willyw
Revered One
Posts: 1196
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

l.kleijn wrote:... it don't work
You need to give a better, more complete description of what is happening.

People here on the forum are not there with you. Can't see whatever you are seeing.

Put yourself in our shoes.
What does "it don't work" mean?

Did the bot crash?
Did you see errors in the partyline?

Is the bind that calls this procedure loaded?
Is its hit counter incrementing?

Any and every detail that you can see, please share it here.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
l
l.kleijn
Voice
Posts: 33
Joined: Sun May 18, 2014 10:02 am

Post by l.kleijn »

I know what the problem was. i forgot the msg to bot. but it's working
Post Reply