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

Re: Is there an idiom for converting an array to an associative array?



On Jan 17,  6:59pm, Matt Armstrong wrote:
> Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:
> 
> >     typeset "assoc[${^array[@]}]=''"
> 
> Thanks, I'll give it a whirl, and then study it for a couple of hours
> to figure out how it works.  :-)

Given array=(a b c), X${^array}Y expands to XaY XbY XcY.  Does that help?

> > }     array=(a b c)
> > }     set -A assoc
> >
> > That should be "typeset -A assoc".  "set -A" means something entirely
> > different.
> 
> I jumped to "To create an empty array (including associative arrays)"
> in the text below:
> 
>        Associative arrays must be declared before assignment, by using:
> 
>               typeset -A name
[...]
>        To create an empty array (including associative arrays), use one of:
> 
>               set -A name

"set -A name" is a form of assignment, not a form of declaration.  Perhaps
the word "create" was poorly chosen in that bit of documentation (and that
remark is the only reason I'm still sending this to zsh-workers).



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