array(n) Tcl Built-In Commands array(n) _________________________________________________________________ NAME array - Manipulate array variables SYNOPSIS array _o_p_t_i_o_n _a_r_r_a_y_N_a_m_e ?_a_r_g _a_r_g ...? _________________________________________________________________ DESCRIPTION This command performs one of several operations on the vari- able given by _a_r_r_a_y_N_a_m_e. Unless otherwise specified for individual commands below, _a_r_r_a_y_N_a_m_e must be the name of an existing array variable. The _o_p_t_i_o_n argument determines what action is carried out by the command. The legal _o_p_t_i_o_n_s (which may be abbreviated) are: array anymore _a_r_r_a_y_N_a_m_e _s_e_a_r_c_h_I_d Returns 1 if there are any more elements left to be processed in an array search, 0 if all elements have already been returned. _S_e_a_r_c_h_I_d indicates which search on _a_r_r_a_y_N_a_m_e to check, and must have been the return value from a previous invocation of array startsearch. This option is particularly useful if an array has an element with an empty name, since the return value from array nextelement won't indicate whether the search has been completed. array donesearch _a_r_r_a_y_N_a_m_e _s_e_a_r_c_h_I_d This command terminates an array search and destroys all the state associated with that search. _S_e_a_r_c_h_I_d indicates which search on _a_r_r_a_y_N_a_m_e to destroy, and must have been the return value from a previous invoca- tion of array startsearch. Returns an empty string. array exists _a_r_r_a_y_N_a_m_e Returns 1 if _a_r_r_a_y_N_a_m_e is an array variable, 0 if there is no variable by that name or if it is a scalar vari- able. array get _a_r_r_a_y_N_a_m_e ?_p_a_t_t_e_r_n? Returns a list containing pairs of elements. The first element in each pair is the name of an element in _a_r_r_a_y_N_a_m_e and the second element of each pair is the value of the array element. The order of the pairs is undefined. If _p_a_t_t_e_r_n is not specified, then all of the elements of the array are included in the result. If _p_a_t_t_e_r_n is specified, then only those elements whose names match _p_a_t_t_e_r_n (using the glob-style matching rules of string match) are included. If _a_r_r_a_y_N_a_m_e isn't the name of an array variable, or if the array Tcl Last change: 7.4 1 array(n) Tcl Built-In Commands array(n) contains no elements, then an empty list is returned. array names _a_r_r_a_y_N_a_m_e ?_p_a_t_t_e_r_n? Returns a list containing the names of all of the ele- ments in the array that match _p_a_t_t_e_r_n (using the glob- style matching rules of string match). If _p_a_t_t_e_r_n is omitted then the command returns all of the element names in the array. If there are no (matching) ele- ments in the array, or if _a_r_r_a_y_N_a_m_e isn't the name of an array variable, then an empty string is returned. array nextelement _a_r_r_a_y_N_a_m_e _s_e_a_r_c_h_I_d Returns the name of the next element in _a_r_r_a_y_N_a_m_e, or an empty string if all elements of _a_r_r_a_y_N_a_m_e have already been returned in this search. The _s_e_a_r_c_h_I_d argument identifies the search, and must have been the return value of an array startsearch command. Warning: if elements are added to or deleted from the array, then all searches are automatically terminated just as if array donesearch had been invoked; this will cause array nextelement operations to fail for those searches. array set _a_r_r_a_y_N_a_m_e _l_i_s_t Sets the values of one or more elements in _a_r_r_a_y_N_a_m_e. _l_i_s_t must have a form like that returned by array get, consisting of an even number of elements. Each odd- numbered element in _l_i_s_t is treated as an element name within _a_r_r_a_y_N_a_m_e, and the following element in _l_i_s_t is used as a new value for that array element. array size _a_r_r_a_y_N_a_m_e Returns a decimal string giving the number of elements in the array. If _a_r_r_a_y_N_a_m_e isn't the name of an array then 0 is returned. array startsearch _a_r_r_a_y_N_a_m_e This command initializes an element-by-element search through the array given by _a_r_r_a_y_N_a_m_e, such that invoca- tions of the array nextelement command will return the names of the individual elements in the array. When the search has been completed, the array donesearch command should be invoked. The return value is a search identifier that must be used in array nextele- ment and array donesearch commands; it allows multiple searches to be underway simultaneously for the same array. KEYWORDS array, element names, search Tcl Last change: 7.4 2