<?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/16624" />

	<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>2009-02-18T16:29:40-04:00</updated>

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

		<entry>
		<author><name><![CDATA[Fill]]></name></author>
		<updated>2009-02-18T16:29:40-04:00</updated>

		<published>2009-02-18T16:29:40-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=87448#p87448</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=87448#p87448"/>
		<title type="html"><![CDATA[Writing, reading and deleting data from a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=87448#p87448"><![CDATA[
thanks guys, you were a great help!!!<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10430">Fill</a> — Wed Feb 18, 2009 4:29 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[TCL_no_TK]]></name></author>
		<updated>2009-02-14T20:53:49-04:00</updated>

		<published>2009-02-14T20:53:49-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=87400#p87400</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=87400#p87400"/>
		<title type="html"><![CDATA[Writing, reading and deleting data from a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=87400#p87400"><![CDATA[
<a href="http://wiki.tcl.tk/17396" class="postlink">http://wiki.tcl.tk/17396</a> Would be a good place to start, however, if you look in the TCL FAQ part of the forum. There is a thread dedicated to File stuff <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_razz.gif" width="15" height="15" alt=":P" title="Razz"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8130">TCL_no_TK</a> — Sat Feb 14, 2009 8:53 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[arfer]]></name></author>
		<updated>2009-02-14T20:51:44-04:00</updated>

		<published>2009-02-14T20:51:44-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=87399#p87399</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=87399#p87399"/>
		<title type="html"><![CDATA[Writing, reading and deleting data from a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=87399#p87399"><![CDATA[
I tend to prefer to keep a complete copy of a file's contents in memory and write it whenever a change is made. Perhaps something like the following code :-<br><div class="codebox"><p>Code: </p><pre><code># call this proc to read the file whatever.txtproc pReadFile {} {    global vFileData    if {[file exists whatever.txt]} {        set id [open whatever.txt r]        set vFileData [split [read -nonewline $id] \n]        close $id    } else {        # handle file doesn't exist    }    return 0}     # call this proc to write the file whatever.txt# the file is first created if it doesn't exist or truncated if it doesproc pWriteFile {} {    global vFileData    if {[info exists vFileData]} {        set id [open whatever.txt w]        puts $id [join $vFileData \n]        close $id    } else {        # handle no data    }    return 0}# call this proc with 1 argument (text to search for in vFileData and if found remove that list item)# only the first list item matching *txt* will be removed# this proc calls pWriteFile if a deletion was madeproc pDeleteLine {txt} {    global vFileData    if {[info exists vFileData]} {        if {[set idx [lsearch $vFileData *$txt*]] != -1} {            set vFileData [lreplace $vFileData $idx $idx]            pWriteFile        } else {            # handle not found        }    } else {        # handle no data    }    return 0}# call this proc with 1 argument (text to add as a list item to vFileData)# this proc calls pWriteFile after the text is appended as a list itemproc pAddLine {txt} {    global vFileData    lappend vFileData $txt    pWriteFile    return 0}</code></pre></div>Workable, as long as the data isn't a monstrous size.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5705">arfer</a> — Sat Feb 14, 2009 8:51 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2009-02-14T20:51:18-04:00</updated>

		<published>2009-02-14T20:51:18-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=87398#p87398</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=87398#p87398"/>
		<title type="html"><![CDATA[Writing, reading and deleting data from a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=87398#p87398"><![CDATA[
Simply put, you can't.<br><br>But... what you can do, is read the whole file into memory, and manipulate the content there. Then you either remove the old file and create a new (empty) one, or reopen the file with the TRUNC option (truncates, clears, the file). Finally, you then write your altered data there.<br><br>Rough example illustrating the process. No actual modification of the data is done here, and no assumptions as to the layout of the data are made.<div class="codebox"><p>Code: </p><pre><code>set fid [open "myfile" "RDONLY"]set data [read $fid]close $fid#manipulate $dataset fid [open "myfile" "WRONLY CREAT TRUNC"]puts $fid $dataclose $fid</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Sat Feb 14, 2009 8:51 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Fill]]></name></author>
		<updated>2009-02-14T19:00:47-04:00</updated>

		<published>2009-02-14T19:00:47-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=87397#p87397</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=87397#p87397"/>
		<title type="html"><![CDATA[Writing, reading and deleting data from a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=87397#p87397"><![CDATA[
Hi,<br><br>I'm making a script that requires writing, reading and deleting entries from a file. With the help of <a href="http://wiki.tcl.tk/367" class="postlink">http://wiki.tcl.tk/367</a>, I was able to make the bot write to a file and read it. However, I don't know how to delete a certain entry.<br><br>I'm using this to write to the file:<br><div class="codebox"><p>Code: </p><pre><code> set data [lrange $text 1 end] set fileId [open Triggers/triggers.$chan "w"] puts -nonewline $fileId $data close $fileId</code></pre></div>How can I make the bot remove a line from the file?<br><br>Thanks in advance,<br>Fill<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10430">Fill</a> — Sat Feb 14, 2009 7:00 pm</p><hr />
]]></content>
	</entry>
	</feed>
