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

	<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-11-28T09:40:41-04:00</updated>

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

		<entry>
		<author><name><![CDATA[dj-zath]]></name></author>
		<updated>2009-11-28T09:40:41-04:00</updated>

		<published>2009-11-28T09:40:41-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=91114#p91114</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=91114#p91114"/>
		<title type="html"><![CDATA[[SOLVED] Calling a varable name from a string of another...]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=91114#p91114"><![CDATA[
hi there Dr. nml!<br><blockquote class="uncited"><div>Both syntaxes are correct. I generally use this syntax, as there is no question as to what I want to do with the file. You can use the short-hand modes, as these map most access-mode combinations..<br><br>Sorry for the stray ], I assume it's the one at the end of the subst-line?</div></blockquote>Yeah, it was the one at the end of the subst line   no problem..  I found it realatively quickly..<br><br>see? I do look carefully- and, at least, try to understand what I'm doing- though I have my flaws <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>you have helped out a LOT on this project... I appreciate that <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>-DjZ-<br><img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"> <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=10318">dj-zath</a> — Sat Nov 28, 2009 9:40 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2009-11-28T09:13:28-04:00</updated>

		<published>2009-11-28T09:13:28-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=91113#p91113</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=91113#p91113"/>
		<title type="html"><![CDATA[[SOLVED] Calling a varable name from a string of another...]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=91113#p91113"><![CDATA[
Both syntaxes are correct. I generally use this syntax, as there is no question as to what I want to do with the file. You can use the short-hand modes, as these map most access-mode combinations..<br><br>Sorry for the stray ], I assume it's the one at the end of the subst-line?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Sat Nov 28, 2009 9:13 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[dj-zath]]></name></author>
		<updated>2009-11-28T08:38:07-04:00</updated>

		<published>2009-11-28T08:38:07-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=91112#p91112</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=91112#p91112"/>
		<title type="html"><![CDATA[[SOLVED] Calling a varable name from a string of another...]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=91112#p91112"><![CDATA[
nml:<br><br>once again, awesome job!<br><br>admittingly, I'm surprised I got as far as I did.. based on that last piece of code that you introduced, I wasn't aware of "file rootname" and "file tail" so you can see <em class="text-italics">why</em> I did what I did.. hmmmmm just  goes to show, I guess .. "newbie" huh? <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>but I admit my wrongs.. and in doing so, I correct them <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>I plugged in your code, and with "adjustments" I have it working seemingly well.. except for an anticipated problem with the playlist.html generation.. but I'm sure I'll figure it out..<br><br>I DO have a "newbie" question..<br><br>your example has "RDONLY" where I changed to 'r' and "WRNG CREAT TRUNC" where I changed to 'w' (and I removed an extra ']' down the line as well)  Now the newbie part..  Was I <em class="text-italics">supposed</em> to??  It seems that was placed there for reasons I can't understand (or, more like the case <em class="text-italics">don't</em> understand...) So I changed, there, what I think, to the "correct" sintax...<br><br>-DjZ-<br><img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"> <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=10318">dj-zath</a> — Sat Nov 28, 2009 8:38 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[dj-zath]]></name></author>
		<updated>2009-11-27T22:26:09-04:00</updated>

		<published>2009-11-27T22:26:09-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=91108#p91108</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=91108#p91108"/>
		<title type="html"><![CDATA[[SOLVED] Calling a varable name from a string of another...]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=91108#p91108"><![CDATA[
Once again, nml.. you da man!<br><br>the moment I <em class="text-italics">saw</em> your example, I noticed what I have done wrong.. (even before your explanation!)  somehow I have "lost my way" somewhere down the line...  I will  most-definately correct this immediately!<br><br>the glob example:<br><br>that ones a bit more to get.. though I am lookiung at the example carefully  and reading your explanation.. this has gone a little past what I understand.. but I will study your example- and  know/understand how it works!<br><br>again, you have been an invalable source of help and advice.. and I owe you many beers <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>-DjZ-<br><img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"> <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=10318">dj-zath</a> — Fri Nov 27, 2009 10:26 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2009-11-28T09:14:57-04:00</updated>

		<published>2009-11-27T14:04:01-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=91095#p91095</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=91095#p91095"/>
		<title type="html"><![CDATA[[SOLVED] Calling a varable name from a string of another...]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=91095#p91095"><![CDATA[
The $out is not the problem, it's the other files you open in the beginning of the proc (in which you don't keep the file handle)... And since you don't keep the file handle, you can't close it...<br><br>Or, [read [open somefile r]] doesn't return a file-handle, but the file contents...<br>Any attempt to close whatever the above returns will fail (except for the extremely unlikely case that the whole content of the file miraculously matches the file handle assigned by tcl, don't ever expect this to occur...).<br><br>Proper way of doing things like this looks like this:<div class="codebox"><p>Code: </p><pre><code>set fchannel [open "thefile" r]set data [read $fchannel]close $fchannel</code></pre></div>See the fundamental difference between $fchannel (file channel identifier) and $data (actual contents of the file "thefile")?<br><br><br>Glob:<br>Glob will return a list of filenames matching the pattern argument.<br>The way I would do a template-system with tcl would go something a little like this:<div class="codebox"><p>Code: </p><pre><code>proc make {} {  foreach $template [glob "templates/*.tmpl"] {    set tmplChan [open $template "RDONLY"]    set htmlChan [open [file join "public_html" "[file rootname [file tail $template]].html"] "WRONLY CREAT TRUNC"]    set tmpl ""    while {![eof $tmplChan]} {      append tmpl [read $tmplChan]    }    puts -nonewline $htmlChan [uplevel #0 [list subst -nobackslashes -nocommands $tmpl]]    close $tmplChan    close $htmlChan  }}</code></pre></div>The above code could of course be extended to move other files than *.tmpl, do timestamp checking, and probably whatever bells'n'whistles you could think of... But for starters, it'll gather a list of files with the extension .tmpl in the templates folder (relative to from where you started your eggdrop), open each file in read-only mode, also opening a second file in write-only mode with the same name but the extension .html, in the public_html folder, read the content of the template, substitute any variables present in the data (in a global context), write the result into the file opened in public_html, and finally close both files and move on to the next one in the list.<br><br><br>"Hanging sockets":<br>This means that you are using synchronous, or blocking, sockets. As I've told you before, use asynchronous sockets and implement a trivial timeout. It's really as simple as that.<br>The http-package will not work well, since the authors failed to implement an asynchronous connection (though once the connection has been established, the script behaves fully asynchronous).<br><br>Edit: Removed stray ] in the last block of code.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Fri Nov 27, 2009 2:04 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[dj-zath]]></name></author>
		<updated>2009-11-27T12:10:36-04:00</updated>

		<published>2009-11-27T12:10:36-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=91093#p91093</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=91093#p91093"/>
		<title type="html"><![CDATA[[SOLVED] Calling a varable name from a string of another...]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=91093#p91093"><![CDATA[
hi nml..  thanks for the reply!<br><br>let's see...<br><br>I DO "close" $Out..  but from what I'm getting from your reply, I'm doing it incorrectly!<br><br>(I DO note that I have seen this error happen on the Verio servers before, too)<br><br>so setting $Var with a "read open..." and then closing Var doesn't close  the file handle?   NOTED!<br><br>hmmmmm<br><br>-sigh-<br><br>seems like I need to scrap all this and start over... AGAIN...<br><br>not like it matters at THIS point.. my website/radio BOMBED..  I've spent TOO much time in "development" (and other issues as well).<br><br>using glob:<br><br>I don't quite understand (at the time of this reading) what you're suggesting.. but I will play with it a bit after I finish up here.... I need to take pre-defined files, read and replace given UNIQUE vars within them and then replace those varables on a writeout to a different file/location<br><br>I didn't think glob would do that on a unique set of different varables based on different files for EACH file<br><br>ex: file-A has $Var1 in it and file-B has $Var2 in it<br><br>need to write-out file-C with the contents of Var-A AND then write out file-D with the contents of $Var-B (while copying EXACTLY the rest of  said files)<br><br>I have played with glob before..and I couldn't get it to work for this operation.. I will play with it some more<br><br>I also tried going back to using standard TCL sockets and stuff on another version.. and all those fun "hanging socket" problems are back!<br><br>I guess its time to open the textbooks on TCL...<br><br>Nah, outside of this bot, theres really no reason to learn it all over again..<br><br>I hate life sometimes! &lt;smirk!&gt;<br><br>-DjZ-<br><img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"> <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=10318">dj-zath</a> — Fri Nov 27, 2009 12:10 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2009-11-17T15:51:07-04:00</updated>

		<published>2009-11-17T15:51:07-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=90947#p90947</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=90947#p90947"/>
		<title type="html"><![CDATA[[SOLVED] Calling a varable name from a string of another...]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=90947#p90947"><![CDATA[
Oh, one more thing..<br>Your code will cause your eggdrop to run out of file handle resources, as it opens file after file without closing them. Probably best describe as a file-handle leak (kind of like a memory leak).<br>Depending on your system, you'd get perhaps 500 calls to "Output" before things starts to break badly...<br><br><strong class="text-strong">Don't use code like this:</strong><div class="codebox"><p>Code: </p><pre><code>set Var [read [open "somefile" r]]</code></pre></div><br>Also, would'nt it be easier to just use the 'glob' command to get a list of .tpl-files, rather having a separate file containing a tcl-list of files?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Tue Nov 17, 2009 3:51 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2009-11-17T13:03:39-04:00</updated>

		<published>2009-11-17T13:03:39-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=90945#p90945</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=90945#p90945"/>
		<title type="html"><![CDATA[[SOLVED] Calling a varable name from a string of another...]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=90945#p90945"><![CDATA[
Sorry, but reading all that text just makes me rather confused..<br>But if I got it all right, what you wanted was to dynamically build dependancies - IE which files depend on which variables?<br><br>For some simple variable names, you could probably get away with a simple regular expression, though in order to cover any valid variable name, you'd need a custom parser.<br><br>For performance, I'd suggest you check file modification timestamp to decide whether the dependancy-list needs updating. Or, if you keep the template in memory, 'trace' the variable containing the template.<br><br>Also, if possible, avoid using all those regsub's... they're resource-hoggers. Using 'subst' with -nocommands should replace all variables within the string in one sweep, without resorting to comples regular expressions...<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Tue Nov 17, 2009 1:03 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[dj-zath]]></name></author>
		<updated>2009-11-16T23:40:18-04:00</updated>

		<published>2009-11-16T23:40:18-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=90942#p90942</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=90942#p90942"/>
		<title type="html"><![CDATA[[SOLVED] Calling a varable name from a string of another...]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=90942#p90942"><![CDATA[
UPDATE:<br><br>I'm going to try doing it all in the "output" proc.. as you suggested-  to load each page, run it through a 'foreach loop', subst it and then write it back to the website..<br><br>thats going to be a LOT of disk activity!<br><br>but, I think I can do that easily enough.. then I don't need to create any global lists or varable sets..<br><br>I'll post the results when I'm done...<br><br>-DjZ-<br><img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"> <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br><br>10 munutes later...<br><br>DONE!<br><br>heres the code:<br><div class="codebox"><p>Code: </p><pre><code>proc    Output {} {          global Csh07 DetIA DetSA DetIV DetSV MyTPL MyWeb;           if {$Csh07 != "$DetIA $DetSA $DetIV $DetSV} {                     set Csh07 "$DetIA $DetSA $DetIV $DetSV;                     foreach VarA [read [open $MyTPL r]] {                            if {(([string first ".tpl" $VarA]) &gt;= "1")} {                                        set VarB [read [open "$MyTPL/$VarA" r]];                                        set VarA [string map {".tpl" ".html"} $VarA];                                        regsub -all -- "\\\$DetIA" $VarB "$DetIA" MetaIDX;                                        regsub -all -- "\\\$DetSA" $MetaIDX "$DetSA" MetaIDX;                                        regsub -all -- "\\\$DetIV" $MetaIDX "$DetIV" MetaIDX;                                        regsub -all -- "\\\$DetSV" $MetaIDX "$DetSV" MetaIDX;                                        set Out [open "$MyWeb/$VarA" w];                                        puts $Out "$MetaIDX";                                        flush $Out;                                        close $Out;                            };                     };           };           return 0;}; </code></pre></div>and there ya have it!<br><br>works.. though I bet the drive light at the server is  blinking like a MoFo hehehe<br><br>it still needs some cleaning up, but thats nothing... I'll have that done long before you get to read this!<br><br>-DjZ-<br><img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"> <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=10318">dj-zath</a> — Mon Nov 16, 2009 11:40 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[dj-zath]]></name></author>
		<updated>2009-11-16T23:32:24-04:00</updated>

		<published>2009-11-16T23:32:24-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=90941#p90941</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=90941#p90941"/>
		<title type="html"><![CDATA[[SOLVED] Calling a varable name from a string of another...]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=90941#p90941"><![CDATA[
hi NML!<br><br>thanks for the reply..<br><br>Actually, thats not where I'm having the problem..<br><br>the problem is READING the template files and loading them into the bot as varables.. this is a unknown value of how many, what they are called  and/or whats in them..<br><br>THEN we need to parse, subst and write them back out to the website...<br><br>this is done on EVERY change thats detected from a list of internal varables..  an example would be all the "status lights" which show up as gif images and the DJs image based on which DJ is on.. etc etc<br><br>if I read/write the directory(ies) EACH time I'm detecting a change, this means a read and write to the drive CONSTANTLY and this REALLY slows things down!<br><br>in the past, I have simply written specific  parser, extract, and subst code for EACH webpage indevidually.. this accounted for a LOT of unessessary code.. and, if I needed to change something on the website, you guessed it  I have to EDIT the bot too!<br><br>SO....<br><br>I thought to only READ the template files at startup and load them into RAM as varable(s).. since those don't change... then only update the webpages when needed..  to do this, I have to "float" an unknown number of GLOBAL varables whos names are not even known untill the bot can detect and read their respected tpl files first. since this happens AFTER the bot is loaded and running...<br><br>its NOT as easy as it sounds!<br><br>I can't seem to take an array's output and assign it as global varables "on the fly" AND I also can't seem to read them from an UNKNOWN list of (non existant) globals later down the line by another proc..<br><br>I see a lot of 'can't find channel named "index  ' errors  (not "index" , "index )<br><br>as for the subst, I have been using regsub.. and THAT part of the code works  VERY nicely.. the varables that need to be subistuted ARE known and are fixed..  thats not the problem!<br><br>example:<br><br>dir /www/TPL<br><br>folder contains 6 files in which 4 are .tpl's<br><br>tpl files are webpages which contain $varables where respected.<br><br>the problem is it can be any number of VARIOUS NAMED files<br><br>index.tpl and playlist.tpl and blowme.tpl etc etc etc<br><br>down the line I may need to add MORE (or take some out)<br><br>thing is if I make them STATIC I'll be editing the bot over and over and over and over.. to make changes in the website!<br><br>I was able to create the array, and get the list of files containing only .tpl extensions..<br><br>I was able to load their contents into said varable(s)<br><br>I was then able to "chop off" the .tpl extension<br><br>but now I can *NOT* take the list of filenames and turn them into GLOBAL VARABLES<br><br>then in another proc...<br><br>I was *NOT* able to read from this "magic list of unknown global varables" and turn them BACK into said filenames containing the internal data whthin each varable<br><br>(next part assumes I create a fake list of website page varables)<br><br>I WAS able to take said varables and  subst/regexp them  to replace the known intenral varables  with the proper values  and then turn them back into webpages. i.e  replace $DetIA with "onair.gif" etc...  this is also done for efficiency- so that the viewer only downloads ONE graphic for all respected varables and not the same graphic, over and over and over,  for EACH varable in the list.<br><br>then I was able to load the webnpages back into /www/web<br><br>well, the array won't "migrate" onto the global list it seems... I'm obviously an idiot... cause Im not getting anywhere... <br><br>-DjZ-<br><img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"> <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=10318">dj-zath</a> — Mon Nov 16, 2009 11:32 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2009-11-16T13:45:48-04:00</updated>

		<published>2009-11-16T13:45:48-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=90938#p90938</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=90938#p90938"/>
		<title type="html"><![CDATA[[SOLVED] Calling a varable name from a string of another...]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=90938#p90938"><![CDATA[
One classic approach for templates would be to use the subst command with appropriate switches. You'll find numerous examples through the forum.<br><br>No need for long lists of variables to substitute, simply open and read the template, do the subst and any variable in the data will be substituted, write the file...<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Mon Nov 16, 2009 1:45 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[dj-zath]]></name></author>
		<updated>2009-11-17T00:21:34-04:00</updated>

		<published>2009-11-16T05:56:11-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=90936#p90936</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=90936#p90936"/>
		<title type="html"><![CDATA[[SOLVED] Calling a varable name from a string of another...]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=90936#p90936"><![CDATA[
ooOOhh!<br><br>ths ones kinda scary to explain..  so I'll explain WHY I have to do this.. perhaps my approach is wrong, and someone can recommend a better way to do it...<br><br>since my eggie actually <em class="text-italics">generates</em> specific and dynamic elements of my website, I came up with an idea to use <strong class="text-strong">TEMPLATE</strong> files instead of just writing mean code into the tcl scripts.. which would mean having to REWRITE the script over and over each time a change to the website was needed...<br><br>I had inital code that took a <em class="text-italics">webpage.tpl</em> file and ran it through some filters to replace given varables with the actual assigned values when needed.. For efficiency, the script worked in modes.. <br><br>first mode:  <em class="text-italics">SetVars</em><br><br>here we load the template fille into a varable ONLY ONCE at startup...<br><div class="codebox"><p>Code: </p><pre><code>proc  setvars {} {        global MyTPL TmpIDX        if {([file exists "$MyTPL/index.tpl"])} {               set TmpIDX "[read [open "$MyTPL/index.tpl" r]]";        }; }; </code></pre></div>now, we only write out the <em class="text-italics">new</em> webpage when a change is detected in the varable strings.. we also parse and filter them as needed:<br><br>Second Mode: <em class="text-italics">Output</em> <br><div class="codebox"><p>Code: </p><pre><code>proc     Output {} {           global TmpIDX MyWeb DetIA DetSA;           if {$Csh01 != "$DetIA $DetSA"} {                set Csh01 "$DetIA $DetSA";                regsub -all -- "\\\$DetIA" $TmpIDX "$DetIA" MetaIDX;                regsub -all -- "\\\$DetSA" $MetaIDX "$DetSA" MetaIDX;                set Out [open "$MyWeb/index.html" w]; puts $Out "$MetaIDX";                flush $Out;                close $Out;           };}; </code></pre></div>now, this works rather nicely, however, theres a small little problem.. I need to STILL have to write in mean code for EACH new webpage that the bot needs to generate!<br><br>that, in itself makes it rather <em class="text-italics">MEANINGLESS</em> to do in the first place!<br><br>So, I started out with a new approach.. to read a directory and generate a list of .tpl files in said dir...<br><div class="codebox"><p>Code: </p><pre><code>foreach VarA [read [open $MyTPL r]] {        if {(([string first ".tpl" $VarA]) &gt;= "1")} {                set VarB [read [open "$MyTPL/$VarA" r]];                set VarA [string map {".tpl" ""} $VarA];                global [read $VarA];                set [read $VarA] $VarB;        };};</code></pre></div>The idea here was to take a list of files, and assign them into varables...<br><br>Then, in Output..<br><div class="codebox"><p>Code: </p><pre><code>foreach VarA [read [open $MyTPL r]] {        if {(([string first ".tpl" $VarA]) &gt;= "1")} {                set VarA [string map {".tpl" ""} $VarA];                global $VarA;                set $VarA [read [open $VarA r]];                regsub -all -- "\\\$DetIA" $VarA "$DetIA" MetaIDX;                regsub -all -- "\\\$DetSA" $MetaIDX "$DetSA" MetaIDX;                set Out [open "$MyWeb/$VarA.html" w];                puts $Out "$MetaIDX";                flush $Out;                close $Out;       };};</code></pre></div><br><br>THIS DOESN'T WORK!<br><br>appariently, i can not assign a string from one varable  as the name of another..and THEN make it global!<br><br>this is where I'm stuck!<br><br>-DjZ<br><img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"> <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=10318">dj-zath</a> — Mon Nov 16, 2009 5:56 am</p><hr />
]]></content>
	</entry>
	</feed>
