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

Re: Associative Arrays don't work



    Hi Ronald :)

 * 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. On the contrary, what I've found
is this:

    "Associative arrays _must_ be declared before assignment..."

> $ zz[f]=4     # Set element f to 4
> $ echo $zz[g] # Request element g (not f). Element g should not be there, but we get 4

    Of course, "g" is zero, so you get the zeroth element from the
array you just vivified.

> $ zz[g]=5     # Set element g to 5
> $ echo $zz[f] # Request element f. We should get 4, but we get 5

    Idem. You assigned to element zero, so you modified 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)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to... RAmen!



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