array.n

来自「tcl是工具命令语言」· N 代码 · 共 142 行

N
142
字号
'\"'\" Copyright (c) 1993-1994 The Regents of the University of California.'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" RCS: @(#) $Id: array.n,v 1.8 2000/09/07 14:27:45 poenitz Exp $'\" .so man.macros.TH array n 8.3 Tcl "Tcl Built-In Commands".BS'\" Note:  do not modify the .SH NAME line immediately below!.SH NAMEarray \- Manipulate array variables.SH SYNOPSIS\fBarray \fIoption arrayName\fR ?\fIarg arg ...\fR?.BE.SH DESCRIPTION.PPThis command performs one of several operations on thevariable given by \fIarrayName\fR.Unless otherwise specified for individual commands below,\fIarrayName\fR must be the name of an existing array variable.The \fIoption\fR argument determines what action is carriedout by the command.The legal \fIoptions\fR (which may be abbreviated) are:.TP\fBarray anymore \fIarrayName searchId\fRReturns 1 if there are any more elements left to be processedin an array search, 0 if all elements have already beenreturned.\fISearchId\fR indicates which search on \fIarrayName\fR tocheck, and must have been the return value from a previousinvocation of \fBarray startsearch\fR.This option is particularly useful if an array has an elementwith an empty name, since the return value from\fBarray nextelement\fR won't indicate whether the searchhas been completed..TP\fBarray donesearch \fIarrayName searchId\fRThis command terminates an array search and destroys all thestate associated with that search.  \fISearchId\fR indicateswhich search on \fIarrayName\fR to destroy, and must havebeen the return value from a previous invocation of\fBarray startsearch\fR.  Returns an empty string..TP\fBarray exists \fIarrayName\fRReturns 1 if \fIarrayName\fR is an array variable, 0 if thereis no variable by that name or if it is a scalar variable..TP\fBarray get \fIarrayName\fR ?\fIpattern\fR?Returns a list containing pairs of elements.  The firstelement in each pair is the name of an element in \fIarrayName\fRand the second element of each pair is the value of thearray element.  The order of the pairs is undefined.If \fIpattern\fR is not specified, then all of the elements of thearray are included in the result.If \fIpattern\fR is specified, then only those elements whose namesmatch \fIpattern\fR (using the matching rules of\fBstring match\fR) are included.If \fIarrayName\fR isn't the name of an array variable, or ifthe array contains no elements, then an empty list is returned..TP\fBarray names \fIarrayName\fR ?\fImode\fR? ?\fIpattern\fR?Returns a list containing the names of all of the elements inthe array that match \fIpattern\fR.  \fIMode\fR may be one of\fB-exact\fR, \fB-glob\fR, or \fB-regexp\fR.  If specified, \fImode\fRdesignates which matching rules to use to match \fIpattern\fR againstthe names of the elements in the array.  If not specified, \fImode\fRdefaults to \fB-glob\fR.  See the documentation for \fBstring match\fRfor information on glob style matching, and the documentation for\fBregexp\fR for information on regexp matching.If \fIpattern\fR is omitted then the command returns all ofthe element names in the array.  If there are no (matching) elementsin the array, or if \fIarrayName\fR isn't the name of an arrayvariable, then an empty string is returned..TP\fBarray nextelement \fIarrayName searchId\fRReturns the name of the next element in \fIarrayName\fR, oran empty string if all elements of \fIarrayName\fR havealready been returned in this search.  The \fIsearchId\fRargument identifies the search, and must havebeen the return value of an \fBarray startsearch\fR command.Warning:  if elements are added to or deleted from the array,then all searches are automatically terminated just as if\fBarray donesearch\fR had been invoked; this will cause\fBarray nextelement\fR operations to fail for those searches..TP\fBarray set \fIarrayName list\fRSets the values of one or more elements in \fIarrayName\fR.\fIlist\fR must have a form like that returned by \fBarray get\fR,consisting of an even number of elements.Each odd-numbered element in \fIlist\fR is treated as an elementname within \fIarrayName\fR, and the following element in \fIlist\fRis used as a new value for that array element.If the variable \fIarrayName\fR does not already existand \fIlist\fR is empty,\fIarrayName\fR is created with an empty array value..TP\fBarray size \fIarrayName\fRReturns a decimal string giving the number of elements in thearray.If \fIarrayName\fR isn't the name of an array then 0 is returned..TP\fBarray startsearch \fIarrayName\fRThis command initializes an element-by-element search through thearray given by \fIarrayName\fR, such that invocations of the\fBarray nextelement\fR command will return the names of theindividual elements in the array.When the search has been completed, the \fBarray donesearch\fRcommand should be invoked.The return value is asearch identifier that must be used in \fBarray nextelement\fRand \fBarray donesearch\fR commands; it allows multiplesearches to be underway simultaneously for the same array..VS 8.4.TP\fBarray statistics \fIarrayName\fRReturns statistics about the distribution of data within the hashtablethat represents the array.  This information includes the number ofentries in the table, the number of buckets, and the utilization ofthe buckets..VE 8.4.VS 8.3.TP\fBarray unset \fIarrayName\fR ?\fIpattern\fR?Unsets all of the elements in the array that match \fIpattern\fR (using thematching rules of \fBstring match\fR).  If \fIarrayName\fR isn't the nameof an array variable or there are no matching elements in the array, noerror will be raised.  If \fIpattern\fR is omitted and \fIarrayName\fR isan array variable, then the command unsets the entire array.The command always returns an empty string..VE 8.3.SH "SEE ALSO"list(n), string(n), variable(n), trace(n).SH KEYWORDSarray, element names, search

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?