Assigning list elements to variables
At this point, we have created, concatenated, joined and appended to our list. Next we need to know how to assign the elements of a list to variables to be able to access the individual elements. To accomplish this, Tcl provides the lassign
command. The syntax is as follows:
lassign list variable1 variable2 …
How to do it…
In the following example, we will assign the elements of our list to a set of variables and print out the values contained within the variables. Return values from the commands are provided for clarity. Enter the following command:
% lassign {John Mary Bill Tom Fred} 1 2 3
Tom Fred
% puts "$1 $2 $3"
John Mary Bill
How it works…
The lassign
command accepts a list as the first argument and assigns ...
Get Tcl/Tk 8.5 Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.