Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
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.

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

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 and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

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