1mNAME0m
       array - Manipulate array variables

1mSYNOPSIS0m
       1marray 4m22moption24m 4marrayName24m ?4marg24m 4marg24m 4m...24m?


1mDESCRIPTION0m
       This  command  performs one of several operations on the variable given
       by 4marrayName24m.   Unless  otherwise  specified  for  individual  commands
       below,  4marrayName24m  must be the name of an existing array variable.  The
       4moption24m argument determines what action is carried out by  the  command.
       The legal 4moptions24m (which may be abbreviated) are:

       1marray anymore 4m22marrayName24m 4msearchId0m
              Returns 1 if there are any more elements left to be processed in
              an array search, 0 if all elements have already  been  returned.
              4mSearchId24m  indicates which search on 4marrayName24m to check, and must
              have been the return value from a previous invocation  of  1marray0m
              1mstartsearch22m.  This option is particularly useful if an array has
              an element with an empty name, since the return value from 1marray0m
              1mnextelement  22mwon't  indicate  whether  the  search has been com-
              pleted.

       1marray donesearch 4m22marrayName24m 4msearchId0m
              This command terminates an array search  and  destroys  all  the
              state  associated  with  that  search.  4mSearchId24m indicates which
              search on 4marrayName24m to destroy, and must have  been  the  return
              value  from a previous invocation of 1marray startsearch22m.  Returns
              an empty string.

       1marray exists 4m22marrayName0m
              Returns 1 if 4marrayName24m is an array variable, 0 if  there  is  no
              variable by that name or if it is a scalar variable.

       1marray get 4m22marrayName24m ?4mpattern24m?
              Returns  a list containing pairs of elements.  The first element
              in each pair is the name of an element in 4marrayName24m and the sec-
              ond element of each pair is the value of the array element.  The
              order of the pairs is undefined.  If 4mpattern24m is  not  specified,
              then  all  of  the  elements  of  the  array are included in the
              result.  If 4mpattern24m is specified, then only those elements whose
              names  match  4mpattern24m (using the matching rules of 1mstring match22m)
              are included.  If 4marrayName24m isn't the name of an array variable,
              or  if  the  array  contains  no elements, then an empty list is
              returned.

       1marray names 4m22marrayName24m ?4mmode24m? ?4mpattern24m?
              Returns a list containing the names of all of  the  elements  in
              the array that match 4mpattern24m.  4mMode24m may be one of 1m-exact22m, 1m-glob22m,
              or 1m-regexp22m.  If specified, 4mmode24m designates which matching  rules
              to use to match 4mpattern24m against the names of the elements in the
              array.  If not specified, 4mmode24m defaults to 1m-glob22m.  See the docu-
              mentation  for 1mstring match 22mfor information on glob style match-
              ing, and the documentation for 1mregexp 22mfor information on  regexp
              matching.  If 4mpattern24m 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 4marrayName24m isn't the name of an array
              variable, then an empty string is returned.

       1marray nextelement 4m22marrayName24m 4msearchId0m
              Returns the name of the next element in 4marrayName24m, or  an  empty
              string  if  all elements of 4marrayName24m have already been returned
              in this search.  The 4msearchId24m argument  identifies  the  search,
              and must have been the return value of an 1marray startsearch 22mcom-
              mand.  Warning:  if elements are added to or  deleted  from  the
              array, then all searches are automatically terminated just as if
              1marray donesearch 22mhad been invoked; this will  cause  1marray  nex-0m
              1mtelement 22moperations to fail for those searches.

       1marray set 4m22marrayName24m 4mlist0m
              Sets the values of one or more elements in 4marrayName24m.  4mlist24m must
              have a form like that returned by 1marray get22m,  consisting  of  an
              even  number  of elements.  Each odd-numbered element in 4mlist24m is
              treated as an element name within 4marrayName24m, and  the  following
              element  in  4mlist24m is used as a new value for that array element.
              If the variable 4marrayName24m does not already  exist  and  4mlist24m  is
              empty, 4marrayName24m is created with an empty array value.

       1marray size 4m22marrayName0m
              Returns  a  decimal  string giving the number of elements in the
              array.  If 4marrayName24m isn't the  name  of  an  array  then  0  is
              returned.

       1marray startsearch 4m22marrayName0m
              This  command  initializes  an element-by-element search through
              the array given by 4marrayName24m, such that invocations of the 1marray0m
              1mnextelement 22mcommand will return the names of the individual ele-
              ments in the array.  When the search  has  been  completed,  the
              1marray donesearch 22mcommand should be invoked.  The return value is
              a search identifier that must be used in 1marray  nextelement  22mand
              1marray  donesearch  22mcommands;  it  allows multiple searches to be
              underway simultaneously for the same  array.   It  is  currently
              more  efficient  and easier to use either the 1marray get 22mor 1marray0m
              1mnames22m, together with 1mforeach22m, to iterate over all but very large
              arrays.  See the examples below for how to do this.

       1marray statistics 4m22marrayName0m
              Returns  statistics  about  the  distribution of data within the
              hashtable that represents the array.  This information  includes
              the  number  of entries in the table, the number of buckets, and
              the utilization of the buckets.

       1marray unset 4m22marrayName24m ?4mpattern24m?
              Unsets all of the elements  in  the  array  that  match  4mpattern0m
              (using  the matching rules of 1mstring match22m).  If 4marrayName24m isn't
              the name of an array variable or there are no matching  elements
              in  the  array,  no error will be raised.  If 4mpattern24m is omitted
              and 4marrayName24m is an array variable, then the command unsets  the
              entire array.  The command always returns an empty string.

1mEXAMPLES0m
              1marray set 22mcolorcount {
                  red   1
                  green 5
                  blue  4
                  white 9
              }

              foreach {color count} [1marray get 22mcolorcount] {
                 puts "Color: $color Count: $count"
              }
               => Color: blue Count: 4
                  Color: white Count: 9
                  Color: green Count: 5
                  Color: red Count: 1

              foreach color [1marray names 22mcolorcount] {
                 puts "Color: $color Count: $colorcount($color)"
              }
               => Color: blue Count: 4
                  Color: white Count: 9
                  Color: green Count: 5
                  Color: red Count: 1

              foreach color [lsort [array names colorcount]] {
                  puts "Color: $color Count: $colorcount($color)"
              }
               => Color: blue Count: 4
                  Color: green Count: 5
                  Color: red Count: 1
                  Color: white Count: 9

              1marray statistics 22mcolorcount
               => 4 entries in table, 4 buckets
                  number of buckets with 0 entries: 1
                  number of buckets with 1 entries: 2
                  number of buckets with 2 entries: 1
                  number of buckets with 3 entries: 0
                  number of buckets with 4 entries: 0
                  number of buckets with 5 entries: 0
                  number of buckets with 6 entries: 0
                  number of buckets with 7 entries: 0
                  number of buckets with 8 entries: 0
                  number of buckets with 9 entries: 0
                  number of buckets with 10 or more entries: 0
                  average search distance for entry: 1.2


1mSEE ALSO0m
       list(n), string(n), variable(n), trace(n), foreach(n)


1mKEYWORDS0m
