Previous section   Next section

Practical Programming in Tcl & Tk, Third Edition
By Brent B. Welch

Table of Contents
Chapter 4.  String Processing in Tcl

The append Command

The append command takes a variable name as its first argument and concatenates its remaining arguments onto the current value of the named variable. The variable is created if it does not already exist:

set foo z
append foo a b c
set foo
=> zabc


The append command is efficient with large strings.

The append command provides an efficient way to add items to the end of a string. It modifies a variable directly, so it can exploit the memory allocation scheme used internally by Tcl. Using the append command like this:

append x " some new stuff"

is always faster than this:

set x "$x some new stuff"

The lappend command described on page 61 has similar performance benefits when working with Tcl lists.

      Previous section   Next section