You can use almost any character for the name of a variable in Tcl — the only restrictions relate to ::
as that is a namespace separator, and (
as that is used for arrays — but the $
syntax is more restrictive; the name it accepts (without using the ${…}
form) has to consist of just ASCII letters, ASCII digits, underscores or namespace separators. Dashes aren't on that list.
The standard (and simplest) way of reading from a variable with a “weird” name is to use set
with only one argument, as that happily accepts any legal variable name at all:
puts "the element is '[set JDSU-12-1(key)]'"
However, if you're doing this a lot it is actually easier to make an alias to the (array) variable name:
upvar 0 JDSU-12-1 theArray
puts "the element is $theArray(key)"
That's exactly how parray
does it, though it uses upvar 1
because it is aliasing to a variable in the calling scope and not in the current scope.