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

Re: uninvited members of associative array




On 2022-12-17 10:19, Roman Perepelitsa wrote:
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.

Right as usual Roman.  The next puzzle is why it was working without that previously.  I had 'IN' declared globally and it was fine.  I'll restore a backup and probe that.  Mind, it's better to have IN local anyway, so maybe I should let sleeping dogs lie.   I don't understand the difference between '-A' and '+A' maybe that's part of it -- the global array might not be overwritten cleanly or something.  But local is best anyway.  Thank you Sensei.






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