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

Re: uninvited members of associative array



On Thu, Dec 15, 2022 at 3:48 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> I just noticed something.  My big array has ten named elements but if I print it:
> ... it all works, however 'elements' 90, 196, 0 and 1 seem to have created themselves

Let's look at the "mystery" elements:

> 90                    main
> 196                  48
> 0                     1
> 1                     48
> List                  1

Now let's pair off the values of the "expected" elements:

> width               90
> window            main

> offset               0
> topE                 1

> active              1
> bottomE           48

> lastE                196
> hight                48

> list                  List
> currentE          1

Notice anything?

I strongly suspect that somewhere you've tried to copy or save/restore
the array by doing something like

list=( $main )
main=( $list )

but have forgotten that for an associative array $main means only the
values, not the keys as well.

Given that you later say "main" is global, you may even have done this
accidentally while working on what you thought was another parameter
named "main", and now you're just finding the leftovers.




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