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

	<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>2011-03-07T14:46:21-04:00</updated>

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

		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2011-03-07T14:46:21-04:00</updated>

		<published>2011-03-07T14:46:21-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96370#p96370</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96370#p96370"/>
		<title type="html"><![CDATA[read from a file ?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96370#p96370"><![CDATA[
<span style="color:red">Since you're not looking for someone just writing code for you, I believe this thread rather belongs to the "Scripting Help" forum (I'll move it there once I'm done with this post)</span><br><br>As for the code, it's not that complex; I'll walk you through it..<div class="codebox"><p>Code: </p><pre><code>if {[catch {open "scripts/chanlist.txt" "RDONLY"} fd]} {  puthelp "PRIVMSG ###1 :Unable to open the channel-list"  putlog "Error during open: $fd"  return 0}</code></pre></div>This simply opens the file in a safe manner. "catch" simply catches any errors thrown by open, allowing us to send an error to the person using the command, and logging the actual error message for further investigation.<br>If the open-command succeeds, a file descriptor is stored in the variable fd instead...<br><div class="codebox"><p>Code: </p><pre><code>fconfigure $fd -blocking 0</code></pre></div>Sets the file descriptor to "non-blocking" mode; which means that no operations on this descriptor may block (blocking == not returning / completing immediately). Usually not needed to be set explicitly with normal files, but it's a good practice in most cases (makes sure your code won't cause your eggie to stop responding in case of I/O issues)<br><div class="codebox"><p>Code: </p><pre><code>while {![eof $fd] &amp;&amp; ![fblocked $fd]} {...}</code></pre></div>Run a loop which checks the EOF (End of File) and fblocked (blocking operation, see above) status of the last operation (in this case; reading a line from the file). EOF will be true if we've reached the end of the file. Fblocked would be true if the last call to "gets" would not return a complete line - not likely to happen with files, but once again good practice (especially if you start reading sockets, serial ports, or pipes in the future).<br>Simply put, this will make sure we keep on reading the file until we've reached the end of it.<br><div class="codebox"><p>Code: </p><pre><code>..if {[gets fd data] &gt; 0 } {  ...}</code></pre></div>Try to read one line from the file, and store it in the variable "data". Also check how many characters we actually read (0 means an empty line, anything less than 0 means there was an error, such as EOF). If we've read something, then we should write it to the channel..<br><div class="codebox"><p>Code: </p><pre><code>...puthelp "PRIVMSG ###1 :$data"...</code></pre></div>Send the line of text we've read into the channel ###1.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Mon Mar 07, 2011 2:46 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2011-03-07T02:24:00-04:00</updated>

		<published>2011-03-07T02:24:00-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96353#p96353</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96353#p96353"/>
		<title type="html"><![CDATA[read from a file ?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96353#p96353"><![CDATA[
@Gemster : You don't need to google anything, just have a look on <a href="http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm" class="postlink">Tcl Commands</a>. All the stuff are explained in there.<br><br>Also, if you checked the <a href="http://forum.egghelp.org/viewforum.php?f=7" class="postlink">Tcl FAQ</a> you would have found <a href="http://forum.egghelp.org/viewtopic.php?t=6885" class="postlink">Basic File Operations</a> where you would have found some interesting stuff to read on this topic.<br><br>Regarding your first post, you don't need to add " in:<div class="codebox"><p>Code: </p><pre><code>puts $cl "[lindex $text 1]" </code></pre></div>unless you want to add two or more variables, like:<div class="codebox"><p>Code: </p><pre><code>puts $cl "$bla $blah" </code></pre></div>or some text:<div class="codebox"><p>Code: </p><pre><code>puts $cl "bla blah" </code></pre></div>@nml375 : no problem. keep up the good work. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Mon Mar 07, 2011 2:24 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Gemster]]></name></author>
		<updated>2011-03-06T19:14:57-04:00</updated>

		<published>2011-03-06T19:14:57-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96350#p96350</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96350#p96350"/>
		<title type="html"><![CDATA[read from a file ?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96350#p96350"><![CDATA[
I know yours does that nml375, but id like to learn this but i cant as i dont understand your script.<br><br>The script i posted i made my self and took a few hours as for googleing everything but the examples i seen for "gets" i just cant get them to work.<br><br>The main reason i need to learn is that there are a lot of script id like to make but they require a file made and read from , this is why i need to learn myself as simple as possible.<br><br>Thanks<br>Gemster<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11375">Gemster</a> — Sun Mar 06, 2011 7:14 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2011-03-06T19:05:39-04:00</updated>

		<published>2011-03-06T19:05:39-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96349#p96349</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96349#p96349"/>
		<title type="html"><![CDATA[read from a file ?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96349#p96349"><![CDATA[
Add the binding<div class="codebox"><p>Code: </p><pre><code>bind pub - ".chanlist" chanlist</code></pre></div>as I said, and that's exactly what it does<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Sun Mar 06, 2011 7:05 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Gemster]]></name></author>
		<updated>2011-03-06T18:53:40-04:00</updated>

		<published>2011-03-06T18:53:40-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96348#p96348</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96348#p96348"/>
		<title type="html"><![CDATA[read from a file ?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96348#p96348"><![CDATA[
I still dont understand that script you posted lol<br><br>Ill i want is a command that will read from a file ?<br><br>Thanks<br>Gemster<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11375">Gemster</a> — Sun Mar 06, 2011 6:53 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2011-03-06T18:39:04-04:00</updated>

		<published>2011-03-06T18:39:04-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96347#p96347</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96347#p96347"/>
		<title type="html"><![CDATA[read from a file ?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96347#p96347"><![CDATA[
caesar:<br>True, thanks for pointing out the typo. Updated the original post.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Sun Mar 06, 2011 6:39 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2011-03-06T18:02:41-04:00</updated>

		<published>2011-03-06T18:02:41-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96346#p96346</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96346#p96346"/>
		<title type="html"><![CDATA[read from a file ?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96346#p96346"><![CDATA[
Shouldn't it be 'fblocked $fd' and not 'fblocked $df'?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Sun Mar 06, 2011 6:02 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2011-03-06T16:39:10-04:00</updated>

		<published>2011-03-06T16:39:10-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96345#p96345</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96345#p96345"/>
		<title type="html"><![CDATA[read from a file ?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96345#p96345"><![CDATA[
That is what my code will do (provided you use the bindning from your original post, simply replacing the "chanlist" proc).<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Sun Mar 06, 2011 4:39 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Gemster]]></name></author>
		<updated>2011-03-06T15:10:41-04:00</updated>

		<published>2011-03-06T15:10:41-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96343#p96343</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96343#p96343"/>
		<title type="html"><![CDATA[read from a file ?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96343#p96343"><![CDATA[
Thanks nml375, but thats kinda too complicated for me to understand atm lol, im new to tcl scripting.<br><br>Is it possible to use the code i posted but will a read command that will msg channel ###1 the output ?<br><br>The file is written as a list like this:<br><br>#channel1<br>#channel2<br>#channel3<br><br>Thanks<br>Gemster<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11375">Gemster</a> — Sun Mar 06, 2011 3:10 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2011-03-06T18:38:03-04:00</updated>

		<published>2011-03-06T14:52:01-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96342#p96342</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96342#p96342"/>
		<title type="html"><![CDATA[read from a file ?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96342#p96342"><![CDATA[
One simple way of doing it is like this:<div class="codebox"><p>Code: </p><pre><code>...proc chanlist {nick uhost hand chan text} {  if {[catch {open "scripts/chanlist.txt" "RDONLY"} fd]} {    puthelp "PRIVMSG ###1 :Unable to open the channel-list"    putlog "Error during open: $fd"    return 0  }  fconfigure $fd -blocking 0  while {![eof $fd] &amp;&amp; ![fblocked $fd]} {    if {[gets $fd data] &gt; 0} {      puthelp "PRIVMSG ###1 :$data"    }  }  close $fd}</code></pre></div>Some prefer using read, split, and foreach instead, which also works..<br><br>Edit: Fixed typo spotted by caesar<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Sun Mar 06, 2011 2:52 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Gemster]]></name></author>
		<updated>2011-03-06T14:02:26-04:00</updated>

		<published>2011-03-06T14:02:26-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=96341#p96341</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=96341#p96341"/>
		<title type="html"><![CDATA[read from a file ?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=96341#p96341"><![CDATA[
Hi, how do i make this read from the file and output it ?<br><div class="codebox"><p>Code: </p><pre><code>bind raw - 322 channel:listproc channel:list {from keyword text} {set cl [open scripts/chanlist.txt a+]puts $cl "[lindex $text 1]" close $cl}bind pub - ".chanlist" chanlistproc chanlist {nick uhost hand chan text} {putserv "list"}</code></pre></div>I need it to msg channel ###1 all lines in that file.<br><br>Thanks<br>Gemster<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11375">Gemster</a> — Sun Mar 06, 2011 2:02 pm</p><hr />
]]></content>
	</entry>
	</feed>
