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

Re: uninvited members of associative array



On Sat, Dec 17, 2022 at 7:11 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
>
> 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

Try this:

    n_input() {
      local -A IN
      set -A IN "${(@Pkv)1}"
    }

Note:

1. IN needs to be declared.
2. Quotes are necessary to handle empty keys and/or values.
3. The extra $ expansion is not necessary.

Roman.




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