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

RE: Associative Arrays don't work



>  * Com MN PG P E B Consultant 3 
> <mn-pg-p-e-b-consultant-3.com@xxxxxxxxxxx> dixit:
> > $ zz=()       # According to zsh doc, should created any 
> array, including associative 
> 
>     I can't find where is that said. 

Having reread http://zsh.sunsite.dk/Doc/Release/zsh_14.html#SEC72 again,
I now see
that we have two contradicting statements about this. The first one is
exactly
like you said:

> 
On the contrary, what I've found
> is this:
> 
>     "Associative arrays _must_ be declared before assignment..."

The second information, further down this section, says:

"To create an empty array (including associative arrays), use one of: 
   set -A name 
   name=()"

When I saw the "use one of", I was happy enough to not read the whole
section verbatim.
Hence, I had chosen the "name=()" form, believing that it would be
sufficient. 

I now see that I has mistakingly believed that creation of an
associative array could
be done without declaring it.

>     Try this:
> 
>     $ typeset -A zz
>     $ zz[f]=4
>     $ zz[g]=5
>     $ print "Here goes zz[f] =>$zz[f] and here zz[g] =>$zz[g]"
>     Here goes zz[f] =>4 and here zz[g] =>5
> 
>     Hope this helps ;) (tested under 4.2.6, BTW)

It does, indeed. Thank you very much!

Ronald
-- 
Ronald Fischer (phone +49-89-63676431)
mailto:mn-pg-p-e-b-consultant-3.com@xxxxxxxxxxx



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