Indexed variables


All objects of class Rexx which are not fixed-dimension arrays support an associative array lookup mechanism (where the index is not constrained to be just integers), equivalent to stems in Rexx. The syntax is the same as for arrays, with one or more index expressions separated by commas within the square brackets. Each index must be a Rexx string (if not, it will be converted to a Rexx string). For example:

  surname='Unknown'           -- default value
  surname['Fred']='Bloggs'
  surname['Davy']='Jones'
  try='Fred'
  say surname[try] surname['Bert']

would say "Bloggs Unknown".

The indexes in the example are single words, however they may be any character string. Index strings are taken 'as-is' -- that is, they must match exactly in case and length for a reference to find a previously-set item.

Before using associative array indexing on a Rexx object, the object must exist; the value of the object is used as the default value whenever an associative reference finds no explicit value.


[ previous section | contents | next section ]

From 'netrexx.doc', version 1.00.
Copyright(c) IBM Corporation, 1996, 1997. All rights reserved. ©