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

Re: Implement an "array index" subscript flag

On Fri, 8 Jun 2018 00:16:20 -0500
dana <dana@xxxxxxx> wrote:
> On 7 Jun 2018, at 20:37, Michael Milton
> <michael.milton@xxxxxxxxxxxxxx> wrote:
> >A useful feature for zsh would be the ability to convert an array
> >into an array of keys/indexes for that array.... Bash has a syntax
> >for this, with the ${!array[@]} expansion  
> zsh actually has the (k) flag for this, but it only works on
> associations.
> I feel like the intuitive thing would be for (k) and (v) to work on
> arrays equivalently to the way they work on associations.

This is reasonable, as far as I can see, but the reason this isn't
an issue in zsh is that unlike bash arrays are really arrays --- in
bash they're basically linked lists, so stored sparsely.  So in zsh
the simple {1..${#array}} is good enough.  "Empty" array elements
in the middle contain a zero length string.  If you really need
sparse storage you have to use an associative array.


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