1 |
578 |
markom |
'\"
|
2 |
|
|
'\" Copyright (c) 1993-1994 The Regents of the University of California.
|
3 |
|
|
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
|
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: array.n,v 1.1.1.1 2002-01-16 10:25:24 markom Exp $
|
9 |
|
|
'\"
|
10 |
|
|
.so man.macros
|
11 |
|
|
.TH array n 7.4 Tcl "Tcl Built-In Commands"
|
12 |
|
|
.BS
|
13 |
|
|
'\" Note: do not modify the .SH NAME line immediately below!
|
14 |
|
|
.SH NAME
|
15 |
|
|
array \- Manipulate array variables
|
16 |
|
|
.SH SYNOPSIS
|
17 |
|
|
\fBarray \fIoption arrayName\fR ?\fIarg arg ...\fR?
|
18 |
|
|
.BE
|
19 |
|
|
|
20 |
|
|
.SH DESCRIPTION
|
21 |
|
|
.PP
|
22 |
|
|
This command performs one of several operations on the
|
23 |
|
|
variable given by \fIarrayName\fR.
|
24 |
|
|
Unless otherwise specified for individual commands below,
|
25 |
|
|
\fIarrayName\fR must be the name of an existing array variable.
|
26 |
|
|
The \fIoption\fR argument determines what action is carried
|
27 |
|
|
out by the command.
|
28 |
|
|
The legal \fIoptions\fR (which may be abbreviated) are:
|
29 |
|
|
.TP
|
30 |
|
|
\fBarray anymore \fIarrayName searchId\fR
|
31 |
|
|
Returns 1 if there are any more elements left to be processed
|
32 |
|
|
in an array search, 0 if all elements have already been
|
33 |
|
|
returned.
|
34 |
|
|
\fISearchId\fR indicates which search on \fIarrayName\fR to
|
35 |
|
|
check, and must have been the return value from a previous
|
36 |
|
|
invocation of \fBarray startsearch\fR.
|
37 |
|
|
This option is particularly useful if an array has an element
|
38 |
|
|
with an empty name, since the return value from
|
39 |
|
|
\fBarray nextelement\fR won't indicate whether the search
|
40 |
|
|
has been completed.
|
41 |
|
|
.TP
|
42 |
|
|
\fBarray donesearch \fIarrayName searchId\fR
|
43 |
|
|
This command terminates an array search and destroys all the
|
44 |
|
|
state associated with that search. \fISearchId\fR indicates
|
45 |
|
|
which search on \fIarrayName\fR to destroy, and must have
|
46 |
|
|
been the return value from a previous invocation of
|
47 |
|
|
\fBarray startsearch\fR. Returns an empty string.
|
48 |
|
|
.TP
|
49 |
|
|
\fBarray exists \fIarrayName\fR
|
50 |
|
|
Returns 1 if \fIarrayName\fR is an array variable, 0 if there
|
51 |
|
|
is no variable by that name or if it is a scalar variable.
|
52 |
|
|
.TP
|
53 |
|
|
\fBarray get \fIarrayName\fR ?\fIpattern\fR?
|
54 |
|
|
Returns a list containing pairs of elements. The first
|
55 |
|
|
element in each pair is the name of an element in \fIarrayName\fR
|
56 |
|
|
and the second element of each pair is the value of the
|
57 |
|
|
array element. The order of the pairs is undefined.
|
58 |
|
|
If \fIpattern\fR is not specified, then all of the elements of the
|
59 |
|
|
array are included in the result.
|
60 |
|
|
If \fIpattern\fR is specified, then only those elements whose names
|
61 |
|
|
match \fIpattern\fR (using the glob-style matching rules of
|
62 |
|
|
\fBstring match\fR) are included.
|
63 |
|
|
If \fIarrayName\fR isn't the name of an array variable, or if
|
64 |
|
|
the array contains no elements, then an empty list is returned.
|
65 |
|
|
.TP
|
66 |
|
|
\fBarray names \fIarrayName\fR ?\fIpattern\fR?
|
67 |
|
|
Returns a list containing the names of all of the elements in
|
68 |
|
|
the array that match \fIpattern\fR (using the glob-style matching
|
69 |
|
|
rules of \fBstring match\fR).
|
70 |
|
|
If \fIpattern\fR is omitted then the command returns all of
|
71 |
|
|
the element names in the array.
|
72 |
|
|
If there are no (matching) elements in the array, or if \fIarrayName\fR
|
73 |
|
|
isn't the name of an array variable, then an empty string is
|
74 |
|
|
returned.
|
75 |
|
|
.TP
|
76 |
|
|
\fBarray nextelement \fIarrayName searchId\fR
|
77 |
|
|
Returns the name of the next element in \fIarrayName\fR, or
|
78 |
|
|
an empty string if all elements of \fIarrayName\fR have
|
79 |
|
|
already been returned in this search. The \fIsearchId\fR
|
80 |
|
|
argument identifies the search, and must have
|
81 |
|
|
been the return value of an \fBarray startsearch\fR command.
|
82 |
|
|
Warning: if elements are added to or deleted from the array,
|
83 |
|
|
then all searches are automatically terminated just as if
|
84 |
|
|
\fBarray donesearch\fR had been invoked; this will cause
|
85 |
|
|
\fBarray nextelement\fR operations to fail for those searches.
|
86 |
|
|
.TP
|
87 |
|
|
\fBarray set \fIarrayName list\fR
|
88 |
|
|
Sets the values of one or more elements in \fIarrayName\fR.
|
89 |
|
|
\fIlist\fR must have a form like that returned by \fBarray get\fR,
|
90 |
|
|
consisting of an even number of elements.
|
91 |
|
|
Each odd-numbered element in \fIlist\fR is treated as an element
|
92 |
|
|
name within \fIarrayName\fR, and the following element in \fIlist\fR
|
93 |
|
|
is used as a new value for that array element.
|
94 |
|
|
If the variable \fIarrayName\fR does not already exist
|
95 |
|
|
and \fIlist\fR is empty,
|
96 |
|
|
\fIarrayName\fR is created with an empty array value.
|
97 |
|
|
.TP
|
98 |
|
|
\fBarray size \fIarrayName\fR
|
99 |
|
|
Returns a decimal string giving the number of elements in the
|
100 |
|
|
array.
|
101 |
|
|
If \fIarrayName\fR isn't the name of an array then 0 is returned.
|
102 |
|
|
.TP
|
103 |
|
|
\fBarray startsearch \fIarrayName\fR
|
104 |
|
|
This command initializes an element-by-element search through the
|
105 |
|
|
array given by \fIarrayName\fR, such that invocations of the
|
106 |
|
|
\fBarray nextelement\fR command will return the names of the
|
107 |
|
|
individual elements in the array.
|
108 |
|
|
When the search has been completed, the \fBarray donesearch\fR
|
109 |
|
|
command should be invoked.
|
110 |
|
|
The return value is a
|
111 |
|
|
search identifier that must be used in \fBarray nextelement\fR
|
112 |
|
|
and \fBarray donesearch\fR commands; it allows multiple
|
113 |
|
|
searches to be underway simultaneously for the same array.
|
114 |
|
|
|
115 |
|
|
.SH KEYWORDS
|
116 |
|
|
array, element names, search
|