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

	<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>2010-07-19T09:05:47-04:00</updated>

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

		<entry>
		<author><name><![CDATA[thommey]]></name></author>
		<updated>2010-07-19T09:05:47-04:00</updated>

		<published>2010-07-19T09:05:47-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=93580#p93580</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=93580#p93580"/>
		<title type="html"><![CDATA[cannot unset an element in an array under certain conditions]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=93580#p93580"><![CDATA[
<blockquote class="uncited"><div><strong class="text-strong">array unset</strong> <em class="text-italics">arrayName ?pattern?</em><br>    Unsets all of the elements in the array that <span style="text-decoration:underline"><strong class="text-strong">match pattern (using the matching rules of <a href="http://www.tcl.tk/man/tcl8.5/TclCmd/string.htm" class="postlink">string match</a>)</strong></span>.<br>-- snip --</div></blockquote> (<strong class="text-strong"><span style="text-decoration:underline">emphasize</span></strong> mine). from <em class="text-italics"><a href="http://www.tcl.tk/man/tcl8.5/TclCmd/array.htm#M15" class="postlink">http://www.tcl.tk/man/tcl8.5/TclCmd/array.htm#M15</a></em>.<br><blockquote class="uncited"><div><strong class="text-strong">string match </strong>?<strong class="text-strong">-nocase</strong>? <em class="text-italics">pattern string</em><br>-- snip --<br>    <strong class="text-strong">[</strong><em class="text-italics">chars</em><strong class="text-strong">]</strong> Matches any character in the set given by <em class="text-italics">chars</em>.<br>-- snip --</div></blockquote>from <em class="text-italics"><a href="http://www.tcl.tk/man/tcl8.5/TclCmd/string.htm#M40" class="postlink">http://www.tcl.tk/man/tcl8.5/TclCmd/string.htm#M40</a></em>.<br><br>And that's why <em class="text-italics">set item {[s]}; array unset myarray $item</em> will unset $myarray(s) only, and is different from <em class="text-italics">unset array($item)</em> which unsets the array element with the literal name "[s]".<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=9830">thommey</a> — Mon Jul 19, 2010 9:05 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willyw]]></name></author>
		<updated>2010-07-18T19:09:21-04:00</updated>

		<published>2010-07-18T19:09:21-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=93574#p93574</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=93574#p93574"/>
		<title type="html"><![CDATA[cannot unset an element in an array under certain conditions]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=93574#p93574"><![CDATA[
It appears that the solution you proposed above, works.   <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br>Thank you.<br><br>Wow... I didn't realize I'd touched on something so deep.<br><br>Thanks for trying to explain.... I'm not sure I got it all, but that's not your fault.<blockquote class="uncited"><div><a href="http://www.peterre.info/characters.html" class="postlink">http://www.peterre.info/characters.html</a><br>This explains how this further affects substitution and evaluation order. So reading it is advised as well. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_wink.gif" width="15" height="15" alt=";)" title="Wink"></div></blockquote>That's the one I mentioned earlier.   It too has some things in it, that even though I've read over it, I don't fully grasp.   It is bookmarked here though.   <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>What was wrong with my trying to use      array unset    though?<br>It sure looked like a workable command, when I looked it up.   Is this just a quirk... that it won't work in this case?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10420">willyw</a> — Sun Jul 18, 2010 7:09 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[speechles]]></name></author>
		<updated>2010-07-14T17:12:51-04:00</updated>

		<published>2010-07-14T17:12:51-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=93539#p93539</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=93539#p93539"/>
		<title type="html"><![CDATA[cannot unset an element in an array under certain conditions]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=93539#p93539"><![CDATA[
<blockquote class="uncited"><div>&lt;speechles&gt; .tcl set my_array(\x5bhello\x5d) "testing testing 1 2 3"<br>&lt;bot&gt; Tcl: testing testing 1 2 3<br>&lt;speechles&gt; .tcl set b $my_array(\x5bhello\x5d)<br>&lt;bot&gt; Tcl: testing testing 1 2 3<br>&lt;speechles&gt; .tcl set a [array names my_array]<br>&lt;bot&gt; Tcl: {[hello]}<br>&lt;speechles&gt; .tcl set my_array(\[hello\]) "\[ is the same as \x5b, but \x5b being evaluation safe ;<strong class="text-strong"></strong>)"<br>&lt;bot&gt; Tcl: [ is the same as [, but [ being evaluation safe ;<strong class="text-strong"></strong>)<br>&lt;speechles&gt; .tcl set a [array names my_array]<br>&lt;bot&gt; Tcl: {[hello]}<br>&lt;speechles&gt; .tcl set b $my_array(\x5bhello\x5d)<br>&lt;bot&gt; Tcl: [ is the same as [, but [ being evaluation safe <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_wink.gif" width="15" height="15" alt=";)" title="Wink"></div></blockquote>This is proof that the parenthesis of the array element are evaluated in the presence of brackets []. The trick is shown above, use the power of evaluation to defeat it. Use the x-encoding value (hex) of the bracket you wish and it effectively becomes an escaped bracket of the exact type you've used, right or left. This same method works for all characters.<br><blockquote class="uncited"><div>doesn't $item appear to TCL as the same info as when I type it in, using no variable?</div></blockquote>The short answer is "NO". Tcl expects a variable to be post processed (known as already evaluated). Whereas your partyline/command-line approach is expected to be pre-processed. Your expected to issue commands, whereas issuing commands from within variables is somewhat rare (..and why [subt]/[eval] with tcl-filters exist). This is why you must use escapes (\), x-encoding(hex), u-encoding(unicode), etc .. to prevent these special characters from influencing Tcl. The long answer is a quiet "...yes", but to explain why would cause a hole in the fabric of time/space and cause a giant rift which might cause the Earth to vanish as if it never existed. So is easier to just say "NO"... <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_biggrin.gif" width="15" height="15" alt=":D" title="Very Happy"><br><br><a href="http://www.peterre.info/characters.html" class="postlink">http://www.peterre.info/characters.html</a><br>This explains how this further affects substitution and evaluation order. So reading it is advised as well. <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=8138">speechles</a> — Wed Jul 14, 2010 5:12 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willyw]]></name></author>
		<updated>2010-07-14T15:19:08-04:00</updated>

		<published>2010-07-14T15:19:08-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=93538#p93538</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=93538#p93538"/>
		<title type="html"><![CDATA[cannot unset an element in an array under certain conditions]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=93538#p93538"><![CDATA[
<blockquote class="uncited"><div><div class="codebox"><p>Code: </p><pre><code>unset array_name($item)</code></pre></div>This will safely unset one element of your array. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_wink.gif" width="15" height="15" alt=";)" title="Wink"></div></blockquote>Thanks for the reply.<br><br><br>With a quick test from the command line in partyline -  yes, it seems to work.<br>But... only if I use the variable.     <br>If I use the exact same info as is contained in the variable, ... just type it in...  then the command fails, as it is trying to evaluate whatever it sees inside the square brackets.<br><br>What's the difference?    this is baffling.    The info is exactly the same.....<br>doesn't $item appear to TCL as the same info as when I type it in, using no variable?<br><br><br>Also, was I doing something wrong,  with using  array unset    ?     It looked like it was the right way to do it,  to me.    I just wonder how I got so far astray. <br><br>I'm headed out to edit my script, and do some testing for real now.<br>I'll comment on how it worked out, later.<br><br>Many thanks.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10420">willyw</a> — Wed Jul 14, 2010 3:19 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[speechles]]></name></author>
		<updated>2010-07-14T14:33:05-04:00</updated>

		<published>2010-07-14T14:33:05-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=93536#p93536</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=93536#p93536"/>
		<title type="html"><![CDATA[cannot unset an element in an array under certain conditions]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=93536#p93536"><![CDATA[
<div class="codebox"><p>Code: </p><pre><code>unset array_name($item)</code></pre></div>This will safely unset one element of your array. <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=8138">speechles</a> — Wed Jul 14, 2010 2:33 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willyw]]></name></author>
		<updated>2010-07-14T12:16:34-04:00</updated>

		<published>2010-07-14T12:16:34-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=93532#p93532</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=93532#p93532"/>
		<title type="html"><![CDATA[cannot unset an element in an array under certain conditions]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=93532#p93532"><![CDATA[
Hello,<br><br>I've taken some ideas, and bits and pieces of script that I've found around, and made myself a script to hold some info, when a user parts the channel.<br><br>Like this:<div class="codebox"><p>Code: </p><pre><code>set array_name([string tolower $nick],$chan) "$nick $uhost $chan [unixtime]"</code></pre></div>Seems to work fine.<br><br>When the user returns to the channel,  script has bot say something like, "Welcome back nick,  it has been  xx minutes(seconds, whatever) since you were last here".<div class="codebox"><p>Code: </p><pre><code>foreach item [array names array_name] {(here, compare hostmask stored in array, to current $host ... if it matches,  then announce, etc.)</code></pre></div>This too, seems to work fine.<br><br>At this point, I want the script to unset the saved info.  To get rid of it.<div class="codebox"><p>Code: </p><pre><code>array unset array_name $item</code></pre></div>This works fine too,  until somebody has a nick with square brackets in it.<br>Usually,  $item would be something like:   somenick,#chan     and it works.<br>However, if the user had a nick with brackets in it:<br>[s]omenick,#chan    - then it doesn't work.<br><br><br>I've played around with [split $item]   and    [join [split $item]]   in the script.<br>No luck. <br><br>Next, I tried doing it "by hand",  in partyline with   .tcl array unset.  I can't get it to unset with:   <br>  .tcl unset array unset [s]omenick,#chan     and it errors with unknown command of course.    <br><br>Next I tried,   .tcl  array unset {[s]omenick,#chan}  and it didn't error...  but it didn't unset it either.<br>So far, the only way I've been able to do it from the partyline command line is:     .tcl array unset {\[s\]omenick,#chan}<br>Using the backslash to escape the brackets does work.<br><br>I thought that if I could manipulate my varname and element such that the element was enclosed in curly braces,  I'd be ok.<br>(  <a href="http://www.peterre.info/characters.html" class="postlink">http://www.peterre.info/characters.html</a>  )<br>Apparently, I'm overlooking something.<br><br>I hope I've made no confusing typos in this post... I've looked at the script so much and tried so many things now, that it is almost all a blur.<br>It is really bugging me now.    <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>If someone could explain to me how to do it, and what my mistake is, I would like that very much.<br><br>Thanks<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10420">willyw</a> — Wed Jul 14, 2010 12:16 pm</p><hr />
]]></content>
	</entry>
	</feed>
