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

	<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>2003-09-01T04:13:54-04:00</updated>

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

		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-31T19:48:15-04:00</updated>

		<published>2003-08-31T19:48:15-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26095#p26095</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26095#p26095"/>
		<title type="html"><![CDATA[Counting Around Empty Lines in a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26095#p26095"><![CDATA[
if you think about it...<div class="codebox"><p>Code: </p><pre><code>proc a {var} {set var}</code></pre></div>only has one command invocation while<div class="codebox"><p>Code: </p><pre><code>proc b {var} {return $var}</code></pre></div> has variable substitution AND a command invocation. So that pretty much explains where the extra cpu cycles go.<br><br>The command invocation is "compiled away" in the lastest version as you mentioned though, but apparently the two methods are still not equally demanding on the cpu. This must be because variable substitution is slower than command invocation in this particular case.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Sun Aug 31, 2003 7:48 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[strikelight]]></name></author>
		<updated>2003-08-31T14:50:48-04:00</updated>

		<published>2003-08-31T14:50:48-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26074#p26074</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26074#p26074"/>
		<title type="html"><![CDATA[Counting Around Empty Lines in a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26074#p26074"><![CDATA[
<blockquote class="uncited"><div>There's a page at the tcl wiki explaining this, but I can't find it right now...i'll post a link to it if I do.</div></blockquote>Found the page:<br><br><a href="http://mini.net/tcl/1044" class="postlink">http://mini.net/tcl/1044</a><br><br>However, it says :<br>set result can <strong class="text-strong">under certain conditions</strong> be equivalent to (or better than)' ..<br><br>It also goes on to say:<br>And in recent versions of Tcl there's no longer a performance penalty for using it (return) either. :^)<br><br>I tried on tcl8.4.1 (which seems pretty recent), but I guess I will have to try on 8.4.4 as well.<br><br>Edit: TCL 8.4.4 Results:<div class="codebox"><p>Code: </p><pre><code>% info patchlevel8.4.4% set aa 2424% proc dd {} {global aa; return $aa}% time dd36 microseconds per iteration% proc dd {} {global aa; set aa}% time dd30 microseconds per iteration</code></pre></div>While it is closer, the 'set' method still appears to be a tad faster. (atleast in this situation)<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2005">strikelight</a> — Sun Aug 31, 2003 2:50 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-31T14:39:38-04:00</updated>

		<published>2003-08-31T14:39:38-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26071#p26071</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26071#p26071"/>
		<title type="html"><![CDATA[Counting Around Empty Lines in a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26071#p26071"><![CDATA[
There's a page at the tcl wiki explaining this, but I can't find it right now...i'll post a link to it if I do.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Sun Aug 31, 2003 2:39 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[strikelight]]></name></author>
		<updated>2003-08-31T14:00:35-04:00</updated>

		<published>2003-08-31T14:00:35-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26062#p26062</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26062#p26062"/>
		<title type="html"><![CDATA[Counting Around Empty Lines in a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26062#p26062"><![CDATA[
<blockquote class="uncited"><div>return use more cpu than set</div></blockquote> I'm just curious as to what you base this on?<br><br>EDIT:<br>Nevermind.. did some tests to verify:<br><div class="codebox"><p>Code: </p><pre><code>% set aa 11% proc dd {} { global aa; return $aa }% set bb [time dd]66 microseconds per iteration% proc dd {} { global aa; set aa }% set bb [time dd]45 microseconds per iteration</code></pre></div>Interesting..<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2005">strikelight</a> — Sun Aug 31, 2003 2:00 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-09-01T04:13:54-04:00</updated>

		<published>2003-08-31T13:43:09-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26060#p26060</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26060#p26060"/>
		<title type="html"><![CDATA[Counting Around Empty Lines in a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26060#p26060"><![CDATA[
<blockquote class="uncited"><div>And what's the point of set i then?</div></blockquote>Making the last returned value inside the proc be the contents of the variable. (set returns the value of the variable when called with one argument) If we were to remove the 'set' line, an empty string would be returned (the value returned by 'close')<br>Get it? <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=2878">user</a> — Sun Aug 31, 2003 1:43 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2003-08-31T13:21:38-04:00</updated>

		<published>2003-08-31T13:21:38-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26057#p26057</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26057#p26057"/>
		<title type="html"><![CDATA[Counting Around Empty Lines in a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26057#p26057"><![CDATA[
And what's the point of set i then?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Sun Aug 31, 2003 1:21 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-31T10:20:10-04:00</updated>

		<published>2003-08-31T10:20:10-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26030#p26030</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26030#p26030"/>
		<title type="html"><![CDATA[Counting Around Empty Lines in a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26030#p26030"><![CDATA[
<blockquote class="uncited"><div>Instead of the last <em class="text-italics">set i</em> i think it should be <em class="text-italics">return $i</em> or something.. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"></div></blockquote>No need for that. (return use more cpu than set)<br><br>Here's why this works (from <a href="http://tcl.tk/man/tcl8.4/TclCmd/proc.htm" class="postlink">http://tcl.tk/man/tcl8.4/TclCmd/proc.htm</a> ):<blockquote class="uncited"><div>When a procedure is invoked, the procedure's return value is the value specified in a return command. If the procedure doesn't execute an explicit return, then its return value is the value of the last command executed in the procedure's body.</div></blockquote><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Sun Aug 31, 2003 10:20 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2003-08-31T10:10:24-04:00</updated>

		<published>2003-08-31T10:10:24-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26028#p26028</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26028#p26028"/>
		<title type="html"><![CDATA[Counting Around Empty Lines in a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26028#p26028"><![CDATA[
Instead of the last <em class="text-italics">set i</em> i think it should be <em class="text-italics">return $i</em> or something.. <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> — Sun Aug 31, 2003 10:10 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-31T09:52:34-04:00</updated>

		<published>2003-08-31T09:52:34-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26021#p26021</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26021#p26021"/>
		<title type="html"><![CDATA[Two ways to do it]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26021#p26021"><![CDATA[
\n+ in the regexp will count several linebreaks next to each other as one, and thus "ignore" the empty lines...<br><div class="codebox"><p>Code: </p><pre><code>proc countNonEmptyLines {file} {set d [read [set f [open $file]]]close $fexpr {[regexp -all \n+ [string trim $d \n]]+1}}</code></pre></div>or if you, for some reason, don't want to keep the entire thing in memory:<br><div class="codebox"><p>Code: </p><pre><code>proc countNonEmptyLines {file} {set f [open $file]set i 0while {[gets $f l]&gt;-1} {if {[string len $l]} {incr i}}close $fset i}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Sun Aug 31, 2003 9:52 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-31T09:32:49-04:00</updated>

		<published>2003-08-31T09:32:49-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26018#p26018</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26018#p26018"/>
		<title type="html"><![CDATA[Counting Around Empty Lines in a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26018#p26018"><![CDATA[
<blockquote class="uncited"><div>But how do I ignore empty lines?</div></blockquote>By only counting the non-empty lines.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Sun Aug 31, 2003 9:32 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-08-31T09:25:52-04:00</updated>

		<published>2003-08-31T09:25:52-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26016#p26016</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26016#p26016"/>
		<title type="html"><![CDATA[Counting Around Empty Lines in a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26016#p26016"><![CDATA[
But how do I ignore empty lines?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Sun Aug 31, 2003 9:25 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-31T09:23:52-04:00</updated>

		<published>2003-08-31T09:23:52-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26014#p26014</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26014#p26014"/>
		<title type="html"><![CDATA[Re: Counting Around Empty Lines in a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26014#p26014"><![CDATA[
Read the file line by line and don't count the empty ones <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=2878">user</a> — Sun Aug 31, 2003 9:23 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Darkj]]></name></author>
		<updated>2003-08-31T08:34:42-04:00</updated>

		<published>2003-08-31T08:34:42-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=26009#p26009</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=26009#p26009"/>
		<title type="html"><![CDATA[Counting Around Empty Lines in a file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=26009#p26009"><![CDATA[
Basically, on rare occasions, sometimes my scripts add blank lines to a file, pretty sure I know how to fix that, but is there a way to count all the lines in the file, but tell it to ignore empty lines.  Thanks.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3459">Darkj</a> — Sun Aug 31, 2003 8:34 am</p><hr />
]]></content>
	</entry>
	</feed>
