1 | '\" |
---|
2 | '\" Copyright (c) 1992-1999 Karl Lehenbauer & Mark Diekhans |
---|
3 | '\" Copyright (c) 2004 Donal K. Fellows |
---|
4 | '\" |
---|
5 | '\" See the file "license.terms" for information on usage and redistribution |
---|
6 | '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
7 | '\" |
---|
8 | '\" RCS: @(#) $Id: lassign.n,v 1.5 2007/12/13 15:22:32 dgp Exp $ |
---|
9 | '\" |
---|
10 | .so man.macros |
---|
11 | .TH lassign n 8.5 Tcl "Tcl Built-In Commands" |
---|
12 | .BS |
---|
13 | '\" Note: do not modify the .SH NAME line immediately below! |
---|
14 | .SH NAME |
---|
15 | lassign \- Assign list elements to variables |
---|
16 | .SH SYNOPSIS |
---|
17 | \fBlassign \fIlist varName \fR?\fIvarName ...\fR? |
---|
18 | .BE |
---|
19 | |
---|
20 | .SH DESCRIPTION |
---|
21 | .PP |
---|
22 | This command treats the value \fIlist\fR as a list and assigns |
---|
23 | successive elements from that list to the variables given by the |
---|
24 | \fIvarName\fR arguments in order. If there are more variable names |
---|
25 | than list elements, the remaining variables are set to the empty |
---|
26 | string. If there are more list elements than variables, a list of |
---|
27 | unassigned elements is returned. |
---|
28 | .SH EXAMPLES |
---|
29 | An illustration of how multiple assignment works, and what happens |
---|
30 | when there are either too few or too many elements. |
---|
31 | .CS |
---|
32 | lassign {a b c} x y z ;# Empty return |
---|
33 | puts $x ;# Prints "a" |
---|
34 | puts $y ;# Prints "b" |
---|
35 | puts $z ;# Prints "c" |
---|
36 | |
---|
37 | lassign {d e} x y z ;# Empty return |
---|
38 | puts $x ;# Prints "d" |
---|
39 | puts $y ;# Prints "e" |
---|
40 | puts $z ;# Prints "" |
---|
41 | |
---|
42 | lassign {f g h i} x y ;# Returns "h i" |
---|
43 | puts $x ;# Prints "f" |
---|
44 | puts $y ;# Prints "g" |
---|
45 | .CE |
---|
46 | The \fBlassign\fR command has other uses. It can be used to create |
---|
47 | the analogue of the |
---|
48 | .QW shift |
---|
49 | command in many shell languages like this: |
---|
50 | .CS |
---|
51 | set ::argv [lassign $::argv argumentToReadOff] |
---|
52 | .CE |
---|
53 | .SH "SEE ALSO" |
---|
54 | lindex(n), list(n), lset(n), set(n) |
---|
55 | |
---|
56 | .SH KEYWORDS |
---|
57 | assign, element, list, multiple, set, variable |
---|