| View previous topic :: View next topic |
| Author |
Message |
l.kleijn Voice
Joined: 18 May 2014 Posts: 33
|
Posted: Sat Apr 13, 2019 4:25 am Post subject: Delete a line |
|
|
| Code: | 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. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Apr 13, 2019 10:08 am Post subject: |
|
|
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: | | set fp [open $fp "w"] | should be changed into | Code: | | 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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
l.kleijn Voice
Joined: 18 May 2014 Posts: 33
|
Posted: Sat Apr 13, 2019 11:29 am Post subject: |
|
|
| Code: | 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. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Apr 13, 2019 11:42 am Post subject: |
|
|
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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
l.kleijn Voice
Joined: 18 May 2014 Posts: 33
|
Posted: Sat Apr 13, 2019 12:38 pm Post subject: |
|
|
| But even with the quote of the original post, change the file you sayd, it don't work |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Sat Apr 13, 2019 3:07 pm Post subject: |
|
|
| 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 ! |
|
| Back to top |
|
 |
l.kleijn Voice
Joined: 18 May 2014 Posts: 33
|
Posted: Sun Apr 14, 2019 2:28 am Post subject: |
|
|
| I know what the problem was. i forgot the msg to bot. but it's working |
|
| Back to top |
|
 |
|