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

Re: uninvited members of associative array




Getting some scent on my troubles with the AA:

I import one AA into another like this:

n_input ()

{

    set -A IN ${(Pkv)${1}} # Copy the array to IN, the working copy.

    typeset -p $1 > /dev/pts/2
    typeset -p IN > /dev/pts/2
....


... and Roman has said this is correct.  For all the functions that call n_input()  everything is fine.  Given the array 'main' as '$1' to the function, typesets show:

typeset -g -A main=( [active]=1 [bottomE]=48 [currentE]=1 [hight]=48 [lastE]=45 [list]=List [offset]=0 [topE]=1 [width]=90 [window]=Main ) typeset -g -A IN     =( [active]=1 [bottomE]=48 [currentE]=1 [hight]=48 [lastE]=45 [list]=List [offset]=0 [topE]=1 [width]=90 [window]=Main )

... perfect.  But there is one exception.  The input array is the same but the output turns into a normal array! Input array is 'files':

typeset -g -A files=( [active]=1 [bottomE]=48 [currentE]=1 [hight]=48 [lastE]=332 [list]=files_list [offset]=0 [topE]=1 [width]=16 [window]=files ) typeset -g -a IN   =( width 16 window files offset 0 topE 1 active 1 bottomE 48 lastE 332 hight 48 list files_list currentE 1 )

... subsequent assignments are obviously going to be haywire and they are as we've discussed.  Now why on earth does that happen? All the keywords are there, and all the values are correct, but needless to say I want it to be an AA, not a normal array.  When 'IN' is written back to the the input array ... sproingggg ....

BTW the order in which the elements are initialized at first go seems unrelated, it doesn't match either typeset.  I thought there might be some artifact in the input values but can see anything. The array consists of two strings and 8 numbers.  Quoting makes no difference.  Options are the same.  I haven't a clue where to go from here.









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