<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/12259" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2006-08-11T11:56:39-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/12259</id>

		<entry>
		<author><name><![CDATA[darton]]></name></author>
		<updated>2006-08-10T14:01:35-04:00</updated>

		<published>2006-08-10T14:01:35-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=65358#p65358</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=65358#p65358"/>
		<title type="html"><![CDATA[Problem with deleting a whole line of a textfile]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=65358#p65358"><![CDATA[
<blockquote class="uncited"><div>I've said that countless times before, but darton just won't listen.</div></blockquote>I am not good in making proper scripts. My scripts work but aren't proper.<img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_wink.gif" width="15" height="15" alt=":wink:" title="Wink"> <br><br>But the script above is proper, isn't it?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=7270">darton</a> — Thu Aug 10, 2006 2:01 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2006-08-10T12:36:09-04:00</updated>

		<published>2006-08-10T12:36:09-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=65357#p65357</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=65357#p65357"/>
		<title type="html"><![CDATA[Problem with deleting a whole line of a textfile]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=65357#p65357"><![CDATA[
I'd guess that'd be the only way of doing it, unless you'd like to mess with temp-files..<br>Oh well, there is random-access mode, but unless you're comfortable coding fixed-size datastructures with lazy-delete, you really don't wanna touch that one <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_wink.gif" width="15" height="15" alt=";)" title="Wink"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Thu Aug 10, 2006 12:36 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[demond]]></name></author>
		<updated>2006-08-10T12:20:56-04:00</updated>

		<published>2006-08-10T12:20:56-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=65356#p65356</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=65356#p65356"/>
		<title type="html"><![CDATA[Problem with deleting a whole line of a textfile]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=65356#p65356"><![CDATA[
I've said that countless times before, but darton just won't listen.<br><br>The (arguably) proper way of using files in eggdrop scripts is:<ul><li>open the file only ONCE, on script's start-up; read the entire content into a list (or array or whatever), then close the file</li><li>manipulate that list as you wish in your event handlers</li><li>periodically SAVE the list into file</li></ul>I've yet to see an eggdrop script having to handle files so large that the above won't work<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5056">demond</a> — Thu Aug 10, 2006 12:20 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2006-08-10T09:14:31-04:00</updated>

		<published>2006-08-10T09:14:31-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=65349#p65349</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=65349#p65349"/>
		<title type="html"><![CDATA[Problem with deleting a whole line of a textfile]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=65349#p65349"><![CDATA[
Yep.<br>If the lines are consecutive, just alter the "last"-argument of lreplace, and it'll replace all elements between "first" and "last" (inclusive).<br><br>If the lines are spread out however, you'll have to use multiple lreplace's.<br>In this case I'd suggest you'd rewrite the script slightly in order to store the result from each lreplace in a variable inbetween the lreplace operations..<br>ie:<div class="codebox"><p>Code: </p><pre><code>set dellist [list "lines" "to" "be" "removed"]...foreach op $dellist { if {[set le [lsearch -exact $list $op]] != -1} {  set list [lreplace $list $le $le] }}puts -nonewline $fd [join $list "\n"]</code></pre></div>Oh, a word of advice, there is a chance that your file will be cleared if you try to remove a line that's not in the file in the example I wrote earlier (my bad). A simple solution would be to only open and close the file a second time if the lsearch is successful (just move the open and close-command inside the if-statement)<div class="codebox"><p>Code: </p><pre><code>  if {[set le [lsearch -exact $list $op]] != -1} {   set fd [open $::adminfile w+]   puts -nonewline $fd [join [lreplace $list $le $le] \n]   close $fd  } else {   putquick "PRIVMSG $chan :Your moderator does not exist."  }</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Thu Aug 10, 2006 9:14 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[darton]]></name></author>
		<updated>2006-08-10T05:52:41-04:00</updated>

		<published>2006-08-10T05:52:41-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=65346#p65346</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=65346#p65346"/>
		<title type="html"><![CDATA[Problem with deleting a whole line of a textfile]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=65346#p65346"><![CDATA[
By the way, is it possible to delete more than one line?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=7270">darton</a> — Thu Aug 10, 2006 5:52 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[darton]]></name></author>
		<updated>2006-08-09T18:17:35-04:00</updated>

		<published>2006-08-09T18:17:35-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=65337#p65337</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=65337#p65337"/>
		<title type="html"><![CDATA[Problem with deleting a whole line of a textfile]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=65337#p65337"><![CDATA[
It works perfectly now. Thank you.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=7270">darton</a> — Wed Aug 09, 2006 6:17 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2006-08-09T17:58:09-04:00</updated>

		<published>2006-08-09T17:58:09-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=65335#p65335</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=65335#p65335"/>
		<title type="html"><![CDATA[Problem with deleting a whole line of a textfile]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=65335#p65335"><![CDATA[
Actually, when you open the file with r+, any writes to the file will append the new data, ie. the file is not truncated pre-write..<br>close it after you've read it, and open it with w+ when you wish to write to it..<div class="codebox"><p>Code: </p><pre><code>bind pub - !delop delopproc delop {nick uhost hand chan arg} { global adminfile if {$arg != ""} {  set op [lindex [split $arg] 0]  set fd [open $::adminfile r+]  while {![eof $fd]} {   lappend list [gets $fd]           }  close $fd  set fd [open $::adminfile w+]  if {[set le [lsearch -exact $list $op]] != -1} {   puts -nonewline $fd [join [lreplace $list $le $le] \n]  } else {   putquick "PRIVMSG $chan :Your moderator does not exist."  }  close $fd }} </code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Wed Aug 09, 2006 5:58 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[darton]]></name></author>
		<updated>2006-08-09T17:43:07-04:00</updated>

		<published>2006-08-09T17:43:07-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=65334#p65334</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=65334#p65334"/>
		<title type="html"><![CDATA[Problem with deleting a whole line of a textfile]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=65334#p65334"><![CDATA[
Exactly the same happens. Another suggestion?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=7270">darton</a> — Wed Aug 09, 2006 5:43 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2006-08-09T17:29:06-04:00</updated>

		<published>2006-08-09T17:29:06-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=65332#p65332</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=65332#p65332"/>
		<title type="html"><![CDATA[Problem with deleting a whole line of a textfile]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=65332#p65332"><![CDATA[
$lines and $list are not the same...<br>lreplace can't alter $list, as it only sees it as variable content, rather than the variable itself. Basically, you could use it without variable aswell, ie:<div class="codebox"><p>Code: </p><pre><code>set mylist [lreplace [list a b c d e] 3 4]</code></pre></div>Try something like this:<div class="codebox"><p>Code: </p><pre><code>bind pub - !delop delopproc delop {nick uhost hand chan arg} { global adminfile if {$arg != ""} {  set op [lindex [split $arg] 0]  set fd [open $::adminfile r+]  while {![eof $fd]} {   lappend list [gets $fd]           }           if {[set le [lsearch -exact $list $op]] != -1} {   puts -nonewline $fd [join [lreplace $list $le $le] \n]   close $fd  } else {   putquick "PRIVMSG $chan :Your moderator does not exist."  } }}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Wed Aug 09, 2006 5:29 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[darton]]></name></author>
		<updated>2006-08-11T11:56:39-04:00</updated>

		<published>2006-08-09T17:16:08-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=65328#p65328</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=65328#p65328"/>
		<title type="html"><![CDATA[Problem with deleting a whole line of a textfile]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=65328#p65328"><![CDATA[
Hello!<br>In the meantime I have managed many things with eggdrop &lt;-&gt; textfiles. But with deleting a line out of a textfile I have a problem. You can see my script here:<div class="codebox"><p>Code: </p><pre><code>bind pub - !delop delopproc delop {nick uhost hand chan arg} {global adminfile if {$arg != ""} {  set op [lindex [split $arg] 0]   set fd [open $::adminfile r+]      while {![eof $fd]} {         lappend list [gets $fd]               }               if {[set le [lsearch -exact $list $op]] != -1} {          #The following line should do the delete stuff, but doesn't          set list [lreplace $list $le $le]          puts -nonewline $fd [join $list \n]          close $fd        } else {          putquick "PRIVMSG $chan :Your moderator does not exist."        } } }</code></pre></div>According to the "<a href="http://forum.egghelp.org/viewtopic.php?t=6885" class="postlink">Basic File Operations</a>" Thread of stdragon a line should be deleted by the following code: "set lines [lreplace $lines $line_to_delete $line_to_delete]". De_Kus said to me that the variable $list and $lines are equivalent. With the line "[set le [lsearch -exact $list $op]]" I am looking for the name $op in the textfile and I am saving the line into the variable $le. So $le and $line_to_delete should be the same, too. But it does not work. The content in the textfile is simply copied and pasted again. <br>Can anybody tell me where the mistake is?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=7270">darton</a> — Wed Aug 09, 2006 5:16 pm</p><hr />
]]></content>
	</entry>
	</feed>
