Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How to preserve order of associative array?



On Nov 7,  5:11pm, Dominik Ritter wrote:
}
} I struggle to the order of an associative array right.

Second paragraph in the doc under "Parameters":

  The attributes of a parameter determine the _type_ of its value, often
  referred to as the parameter type or variable type, and also control
  other processing that may be applied to the value when it is referenced.
  The value type may be a _scalar_ (a string, an integer, or a floating
  point number), an array (indexed numerically), or an _associative_
  array (an unordered set of name-value pairs, indexed by name, also
  referred to as a _hash_).

You can simulate an ordered set of name-value pairs like this (need zsh
version 5.1 for assigning to an array during typeset):

    typeset -a ord_array=(one 1 two 2 three 3 four 4)
    print ${ord_array[ord_array[(i)three]+1]}



Messages sorted by: Reverse Date, Date, Thread, Author