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

Re: Associative Arrays



On Fri, 22 Oct 2004, Stephane Chazelas wrote:

> On Thu, Oct 21, 2004 at 09:40:14AM -0700, Bart Schaefer wrote:
> [...]
> >    local -A named; set -A named "$@"
> [...]
> 
> That's not correct as "$@" may have "-x"/"-e" like elements.

You'd be right if we weren't talking about zsh.  From the doc for "set":

     The behaviour of arguments after -A NAME or +A NAME depends on
     whether the option KSH_ARRAYS is set.  If it is not set, all
     arguments following NAME are treated as values for the array,
     regardless of their form.  If the option is set, normal option
     processing continues at that point; only regular arguments are
     treated as values for the array.  This means that

          set -A array -x -- foo

     sets array to `-x - foo' if KSH_ARRAYS is not set, but sets the
     array to foo and turns on the option `-x' if it is set.

> ksh has:
> 
> set -A named -- "$@"
> 
> it doesn't seem to work in zsh 4.2.0.

See above.

> named=("$@")
> 
> is OK though.

I'll agree it's better because it doesn't vary with KSH_ARRAYS.



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