Main Content

Tcl variable names - no real limits!

Archive - Originally posted on "The Horse's Mouth" - 2015-03-10 15:31:14 - Graham Ellis

In Tcl, there are no limits as to what you use as a vaiable name in Tcl, although I would reommend that you stick with "letter, followed by letters, digits, underscores". Here are some examples of thinks you can, but should not, write:

  % set " " ohdear!
  ohdear!
  % puts ${ }
  ohdear!
  %
  
  %
  % set 7 34
  34
  % puts
  34
  %
  
  % set print puts
  puts
  %
  % $print "Hello World"
  Hello World
  %


Remember that in Tcl, you put s $ in front of a varioable name if you're just using the existing content, and no $ if you;re setting (or in a syntax where it will possibly be set)