Training, Open Source computer languages

This is page http://www.wellho.net/forum/The-Tcl- ... guage/forcing-variable-not-command-substitution.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
forcing variable (not command) substitution?

Posted by that_guy (that_guy), 25 July 2003
Hi. I've made a scrolledframe that  is populated with entryfields "on the fly" with field names/values from a database. The fields/values correspond to program flags "-c  -f  -l", and arguments. In the database, for each flag I'm also storing whether it's a short option or long(requiring an argument). If I have a short option, I want to create a checkbutton instead of an entryfield. So far all of this works. The problem now is just that I want to do something like
$entry configure -text $name -variable "$chost$name"
I'm using the values from the textfields and checkboxes to build up a string like "iperf -c  --len 5", so later on I want to retrieve the state of the checkbutton from its variable. How can I force something like eval $"$chost$name" to work? If I use eval it will complain this is not a command.  Thanks so much  for any insight

So I found the subst command, unfortunately  I also found out  that TCL variables cannot have hyphens in them. I ran out of ideas as to how to do this nicely- so I ended up doing a regsub -all -- - on  the name before defining a variable.  


Posted by admin (Graham Ellis), 26 July 2003
Tcl variables can include any special characters that you like includeing the hyphen, but you need to protect them from the interpretter by writing the variable name in curly braces.  It is something I would suggest you don't do, but it is possible.

Code:
bash-2.04$ tcl
tcl>set fred 20
tcl>set fred
20
tcl>set {fred-again} 30
tcl>set {fred-again}
30
tcl>puts "$fred --- ${fred-again} +++"
20 --- 30 +++
tcl>



In the earlier part of your question, you are tying a variable who's name is $chost$name to your data entry box.   You don't need to do any sort of eval on it as (as it correctly complains), it's not a command but a variable.  At every point once you've built your GUI, it contains a copy of what's actually displayed in the entry box, and you can use it just as an ordinary variable - for example you could write
          lappend  mylist  $"$chost$name"
if you wanted to add it to a list



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho