Performing variable substitution
Now that we have mapped, formatted, counted, analyzed, and generally picked our strings apart, let's look at programmatically performing variable substitution in a string. As Tcl always seems to do, we have been provided with a powerful command to simplify the task with the subst
command. While you could easily invoke the set
command to change the contents, subst
provides the ability to alter portions of a variable by providing optional switches.
The syntax of the subst
command is as follows:
subst switch string
The subst
command performs variable substitution to a string. The behavior may be controlled with optional switches.
These switches are as follows:
Switch |
Description |
---|---|
|
No backslash substitution will be performed. |
|
No command substitution will be performed. |
|
No variable substitution will be performed. |
How to do it…
In the following example, we will create a string that contains the value of a variable...