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

	<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-08-13T01:48:44-04:00</updated>

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

		<entry>
		<author><name><![CDATA[strikelight]]></name></author>
		<updated>2003-08-13T01:48:44-04:00</updated>

		<published>2003-08-13T01:48:44-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=24813#p24813</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=24813#p24813"/>
		<title type="html"><![CDATA[split ||]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=24813#p24813"><![CDATA[
<blockquote class="uncited"><div><br>O(8n) = O(2n) = O(n) (you ignore constants). That's why I said both are O(n).<br></div></blockquote>  Yes, this is true.. However, because tcl execution is quite slow in comparison to compiled languages, the coefficients become increasingly harder to simply discard.<br><blockquote class="uncited"><div>Also, what does comparing regsub and string map have to do with anything? Ppslim's original proc didn't use regsub so I don't see where that comparison is going.. but even so, it's wrong, because regsub is not always O(n), it can be higher, like O(n^2) for certain operations, or lower, like O(1) for other operations.</div></blockquote>I brought it up as a comparison for the short 'chop' procedure...<br>ie. regsub -all $by $str $re str   in place of the string map...<br><br>So either (from timed results):<br>a) regsub does extra work to do the same thing as done by the string map (&gt; O(n))<br>b) string map doesn't take an iterative-search approach to implementing it's changes (&lt; O(n))<br><br>Nitpick nitpicked nitpicked nitpick nitpick nitpicked  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_surprised.gif" width="15" height="15" alt=":o" title="Surprised"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2005">strikelight</a> — Wed Aug 13, 2003 1:48 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[stdragon]]></name></author>
		<updated>2003-08-13T01:28:27-04:00</updated>

		<published>2003-08-13T01:28:27-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=24809#p24809</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=24809#p24809"/>
		<title type="html"><![CDATA[split ||]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=24809#p24809"><![CDATA[
<blockquote class="uncited"><div><blockquote class="uncited"><div>Just to nitpick, you're assuming that the operations in question have the same penalty time-wise, but that's wrong. If you think about it, "string map" and "split" both cycle through the entire string searching. Both procs are O(n).</div></blockquote>I was referring to the 'string map' versus the proc initially proposed by ppslim, which uses a while loop, as well as many other functions, which is obviously going to require a larger O notation.</div></blockquote>I was referring to those two procs too. Ppslim's does not require a bigger O notation, because "string map" is itself a function that uses a loop and many other functions. It is not a constant-time function.  So the two procs are basically the same in terms of efficiency -- although ppslim's is slower overall because it's implemented in tcl instead of C. That doesn't change its O value.<br><blockquote class="uncited"><div>And if you are referring to the proc which does use both split and string map and my calculation of big-O, you will see the word 'about' in my estimation (which is what O notation is).. It would be O(n+n) = O(2n) then.. and even then it's probably less, because when you think about it, if you were to use regsub in place of string map, you would find it takes longer in practical tests.. so assuming the regsub would be O(n), then string map &lt; O(n) .. Nitpick nitpicked.</div></blockquote>O(8n) = O(2n) = O(n) (you ignore constants). That's why I said both are O(n).<br><br>Just to clear this up: the purpose of big-O notation is to estimate the change in something like memory usage or running time relative to a change in input (n). In this case we're talking about string length. So if you double the string length, an O(n) algorithm will take double the time to finish. You can see that (2n) / (n) = 2, twice the time. If you have O(8n), you get (8 * 2n) / (8 * n) = 2 (same as O(n)). If you have an O(n^2) algorithm, you get ((2n)^2) / (n^2) = 4, which means it takes 4 times as long when you double the input.<br><br>Also, what does comparing regsub and string map have to do with anything? Ppslim's original proc didn't use regsub so I don't see where that comparison is going.. but even so, it's wrong, because regsub is not always O(n), it can be higher, like O(n^2) for certain operations, or lower, like O(1) for other operations.<br><br>nitpicked nitpick nitpick nitpicked :)<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8">stdragon</a> — Wed Aug 13, 2003 1:28 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-12T22:53:09-04:00</updated>

		<published>2003-08-12T22:53:09-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=24802#p24802</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=24802#p24802"/>
		<title type="html"><![CDATA[Re: Slight bug]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=24802#p24802"><![CDATA[
<blockquote class="uncited"><div>Hence the \x81 furthur on..</div></blockquote>I still don't get it.<blockquote class="uncited"><div>O-notation is largely used in computer science... To call it sensless, is pure ignorance. I suggest researching "O Notation" on google.</div></blockquote>I didn't call O-notation senseless. What I meant is that it's very inaccurate when used on the uncompiled tcl code.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Tue Aug 12, 2003 10:53 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[strikelight]]></name></author>
		<updated>2003-08-12T22:43:19-04:00</updated>

		<published>2003-08-12T22:43:19-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=24801#p24801</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=24801#p24801"/>
		<title type="html"><![CDATA[Re: Slight bug]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=24801#p24801"><![CDATA[
<blockquote class="uncited"><div><blockquote class="uncited"><div>It most definitley is better for ANY text...</div></blockquote>Not if the text can contain any char. Then it's useless.</div></blockquote>Hence the \x81 furthur on..<br><blockquote class="uncited"><div><blockquote class="uncited"><div>the previous implementation would render approximately O(8n) instructions whereas the second one only renders about O(3) instructions ... so if the text was 128 chars long, the first one would be issuing about 384 instructions (worst case scenario) to the processor, as opposed to the mere 3 instructions sent out by the shorter proc.</div></blockquote>By "instructions" I assume you mean command invocations, and counting them, like stdragon said, makes little sense.</div></blockquote> O-notation is largely used in computer science... To call it sensless, is pure ignorance. I suggest researching "O Notation" on google.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2005">strikelight</a> — Tue Aug 12, 2003 10:43 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-12T22:34:16-04:00</updated>

		<published>2003-08-12T22:34:16-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=24800#p24800</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=24800#p24800"/>
		<title type="html"><![CDATA[Re: Slight bug]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=24800#p24800"><![CDATA[
<blockquote class="uncited"><div>It most definitley is better for ANY text...</div></blockquote>Not if the text can contain any char. Then it's useless.<blockquote class="uncited"><div>the previous implementation would render approximately O(8n) instructions whereas the second one only renders about O(3) instructions ... so if the text was 128 chars long, the first one would be issuing about 384 instructions (worst case scenario) to the processor, as opposed to the mere 3 instructions sent out by the shorter proc.</div></blockquote>By "instructions" I assume you mean command invocations, and counting them, like stdragon said, makes little sense.<br><br>Why think when we've got "time"? <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_razz.gif" width="15" height="15" alt=":P" title="Razz"> I named the three procs from this thread in the order they were posted and timed them:<div class="codebox"><p>Code: </p><pre><code>set a "ab||cde||fghi||jklmn||opqrst||uvwxyz0||12345678||"foreach cmd {chop1 chop2 chop3} {  puts "$cmd: [time [list $cmd $a ||] 10000]"}</code></pre></div>Result:<blockquote class="uncited"><div>chop1: 377 microseconds per iteration<br>chop2: 118 microseconds per iteration<br>chop3: 36 microseconds per iteration</div></blockquote><blockquote class="uncited"><div>Although I would have used \x81 instead of \0 myself <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_wink.gif" width="15" height="15" alt=";)" title="Wink"></div></blockquote>WHY?<br>\x81 can be sent via irc, \0 can't. (unless it's encoded in a ctcp iirc) That's my reason for using \0.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Tue Aug 12, 2003 10:34 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[strikelight]]></name></author>
		<updated>2003-08-12T22:09:21-04:00</updated>

		<published>2003-08-12T22:09:21-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=24799#p24799</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=24799#p24799"/>
		<title type="html"><![CDATA[split ||]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=24799#p24799"><![CDATA[
<blockquote class="uncited"><div>Just to nitpick, you're assuming that the operations in question have the same penalty time-wise, but that's wrong. If you think about it, "string map" and "split" both cycle through the entire string searching. Both procs are O(n).</div></blockquote>I was referring to the 'string map' versus the proc initially proposed by ppslim, which uses a while loop, as well as many other functions, which is obviously going to require a larger O notation. <br>And if you are referring to the proc which does use both split and string map and my calculation of big-O, you will see the word 'about' in my estimation (which is what O notation is).. It would be O(n+n) = O(2n) then.. and even then it's probably less, because when you think about it, if you were to use regsub in place of string map, you would find it takes longer in practical tests.. so assuming the regsub would be O(n), then string map &lt; O(n) .. Nitpick nitpicked.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2005">strikelight</a> — Tue Aug 12, 2003 10:09 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[stdragon]]></name></author>
		<updated>2003-08-12T21:18:39-04:00</updated>

		<published>2003-08-12T21:18:39-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=24798#p24798</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=24798#p24798"/>
		<title type="html"><![CDATA[split ||]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=24798#p24798"><![CDATA[
Just to nitpick, you're assuming that the operations in question have the same penalty time-wise, but that's wrong. If you think about it, "string map" and "split" both cycle through the entire string searching. Both procs are O(n).<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8">stdragon</a> — Tue Aug 12, 2003 9:18 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[strikelight]]></name></author>
		<updated>2003-08-12T14:19:12-04:00</updated>

		<published>2003-08-12T14:19:12-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=24784#p24784</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=24784#p24784"/>
		<title type="html"><![CDATA[Re: Slight bug]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=24784#p24784"><![CDATA[
<blockquote class="uncited"><div>This check:<blockquote class="uncited"><div>  if {[string length [string range $in $chunks end]]} {</div></blockquote>will lead to invalid results if the last chars of the string is the chars you're "splitting" by. (should result in a empty element at the end)<br><br>Here's a rewrite of ppslim's proc that should produce results more like the original split:<br><div class="codebox"><p>Code: </p><pre><code>proc chop {str {by " "}} {set l [string length $by]set i 0set j 0while {[set j [string first $by $str $i]]&gt;-1} {lappend out [string range $str $i [expr {$j-1}]]set i [expr {$j+$l}]}if {$i&lt;=[string len $str]} {lappend out [string range $str $i end]}set out}</code></pre></div>EDIT: I still think <div class="codebox"><p>Code: </p><pre><code>proc chop {str {by "  "} {re \0}} {  split [string map [list $by $re] $str] $re}</code></pre></div> is better (at least for text recieved from irc) <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"></div></blockquote>It most definitley is better for ANY text... not only because of code size, but also cpu time wise.. the previous implementation would render approximately O(8n) instructions whereas the second one only renders<br>about O(3) instructions ... so if the text was 128 chars long, the first one would be issuing about 384 instructions (worst case scenario) to the processor, as opposed to the mere 3 instructions sent out by the shorter proc.  Although I would have used \x81 instead of \0 myself <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=2005">strikelight</a> — Tue Aug 12, 2003 2:19 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-12T09:29:08-04:00</updated>

		<published>2003-08-12T09:29:08-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=24764#p24764</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=24764#p24764"/>
		<title type="html"><![CDATA[Slight bug]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=24764#p24764"><![CDATA[
This check:<blockquote class="uncited"><div>  if {[string length [string range $in $chunks end]]} {</div></blockquote>will lead to invalid results if the last chars of the string is the chars you're "splitting" by. (should result in a empty element at the end)<br><br>Here's a rewrite of ppslim's proc that should produce results more like the original split:<br><div class="codebox"><p>Code: </p><pre><code>proc chop {str {by " "}} {set l [string length $by]set i 0set j 0while {[set j [string first $by $str $i]]&gt;-1} {lappend out [string range $str $i [expr {$j-1}]]set i [expr {$j+$l}]}if {$i&lt;=[string len $str]} {lappend out [string range $str $i end]}set out}</code></pre></div>EDIT: I still think <div class="codebox"><p>Code: </p><pre><code>proc chop {str {by "  "} {re \0}} {  split [string map [list $by $re] $str] $re}</code></pre></div> is better (at least for text recieved from irc) <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> — Tue Aug 12, 2003 9:29 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ppslim]]></name></author>
		<updated>2003-08-12T07:54:50-04:00</updated>

		<published>2003-08-12T07:54:50-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=24756#p24756</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=24756#p24756"/>
		<title type="html"><![CDATA[split ||]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=24756#p24756"><![CDATA[
<div class="codebox"><p>Code: </p><pre><code>proc chunk {in chars} {  if {[string first $chars $in] &lt; 0} { return [list $in] }  set temp [list]  set chunks 0  set chunke 0  while {[set chunke [string first $chars $in $chunks]] != "-1"} {    lappend temp [string range $in $chunks [expr $chunke - 1]]    set chunks [expr $chunke + [string length $chars]]  }  if {[string length [string range $in $chunks end]]} {    lappend temp [string range $in $chunks end]  }  return $temp}</code></pre></div>Simalar to split, however, it does it in chunks like you asked.<br><blockquote class="uncited"><div>% set a "123,@.456,@.789,@.abc,@.def,&gt;.ghi,@.jklm"<br>123,@.456,@.789,@.abc,@.def,&gt;.ghi,@.jklm<br><br>% chunk $a ",@."<br>123 456 789 abc def,&gt;.ghi jklm<br><br>% chunk $a ",&gt;."<br>123,@.456,@.789,@.abc,@.def ghi,@.jklm</div></blockquote><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2">ppslim</a> — Tue Aug 12, 2003 7:54 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-08-11T09:28:15-04:00</updated>

		<published>2003-08-11T09:28:15-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=24713#p24713</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=24713#p24713"/>
		<title type="html"><![CDATA[split ||]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=24713#p24713"><![CDATA[
Check the <a href="http://tcl.tk/man/tcl8.4/TclCmd/split.htm" class="postlink">manual</a>.<br>'split' splits on ALL the chars specified in the second argument (if any).<div class="codebox"><p>Code: </p><pre><code>regexp -all -inline {[^|]+} $yourString</code></pre></div> would return a list like you want, but doesn't care how many |'s there are between the "elements".<br>Another solution is replacing || with some single char not used anywhere else in your content (using 'string map' or 'regsub') and then split by that char.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Mon Aug 11, 2003 9:28 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[arcane]]></name></author>
		<updated>2003-08-11T08:58:20-04:00</updated>

		<published>2003-08-11T08:58:20-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=24711#p24711</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=24711#p24711"/>
		<title type="html"><![CDATA[split ||]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=24711#p24711"><![CDATA[
hi<br>anyone a solution for this:<br><br>i've got a string "a||b||c||d" and i want to split it into a, b, c and d. now my problem is that tcl won't split by "||". it just splits by "|" and gives me too much parts.<br><div class="codebox"><p>Code: </p><pre><code>set test "a||b||c||d"set length [llength [split $test "||"]]</code></pre></div>length is now "7".<div class="codebox"><p>Code: </p><pre><code>set test "a|b|c|d"set length [llength [split $test "||"]]</code></pre></div>length is now "4".<br><br>i've tried everything i could think of (split "\\||", split {||}, split "\|\|"...). none did work. can you help me?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2617">arcane</a> — Mon Aug 11, 2003 8:58 am</p><hr />
]]></content>
	</entry>
	</feed>
