Navigation Logo 2.6  Double Quotes Navigation Logo

 

 

Double quotes in Tcl have a meaning that is both familiar and strange. Often, they are used to define strings, as in "Hello World" – that is what is familiar. A cleaner way to write the same string is usually {Hello World} -- that is what is strange.

You saw the use of curly brackets in the previous section. Double quotes are much the same but different in that:

  • When an argument is surrounded by double quotes, substitutions are performed – use the curly brackets when you do not want substitution and use double quotes when you do.

  • Curly brackets can be nested whereas double quotes cannot.
Be aware that it is what surrounds your argument that determines whether curly-bracket or double-quote processing will apply.

Exercise 2.6a

What is output by the following?
set X Hello
puts {$X World}
puts "$X World"
puts { {Hello} {World} }
puts " {Hello} {World} "

Solution

 

 

[Sample TK Application]
Author's Home Page
Navigation Logo [Book's Cover]
Order from Amazon.