Hi all,
A useful feature for zsh would be the ability to convert an array into an array of keys/indexes for that array. For example, converting (a b c d) into (1 2 3 4)
Bash has a syntax for this, with the ${!array[@]} expansion, e.g.
vals=(a b c d)
keys=${!ids[@]}
Could we perhaps add another "Subscript Flag" to zsh, such that it evaluates the array into its indexes? For example, it might be ${(x)array[@]}, such that you could use it like this:
vals=(a b c d)
keys=${(x)ids[@]}
I suspect there is some desire for a feature like this, because there is a StackExchange question on the subject for zsh: https://unix.stackexchange.com/questions/334048/obtain-the-index-of-the-array,
as well as a very high profile question for bash: https://stackoverflow.com/questions/6723426/looping-over-arrays-printing-both-index-and-value.
I'd be happy to contribute such a feature but I'm not sure what the contribution process actually is.
|