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

Re: get keys of an associative array?



On Sun, 26 Mar 2017 21:18:28 +0200
Jens Elkner <jel+zsh@xxxxxxxxxxxxxxxxxxx> wrote:
> I've KSH_ARRAYS (beside KSH_GLOB KSH_TYPESET KSH_OPTION_PRINT) set,
> however, getting the key set of an array via ${!vname[@]} (as usually
> done within ksh or bash) does not work (bad substitution).

That's never been implemented; it may be too far away from how zsh works
to do usefullly.

> Couldn't find anything else, except the @k flag, but this doesn't work
> as well, e.g.
> 
> unset A; typeset -A A; A['a']=1; A['b']=2; A['c']=3 ; print "${(@k)A}"
> 
> should print 'a b c' but prints '3'. Bug, feature? Hmmm, any hints?

You need "${(k)A[@]}" in ksh mode, but I'm not sure why the (@) flag
doesn't do the trick.  As it's an associative array you get the keys
back unordered.

pws



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