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

Re: Implement an "array index" subscript flag



On 8 Jun 2018, at 00:46, Michael Milton <michael.milton@xxxxxxxxxxxxxx> wrote:
>This produces no output:
>arr=([1]=a [2]=b)
>keys=${arr[(k)@]}
>echo $keys

You're talking about the (k) subscript flag; i meant the (k) expansion flag. See
the hypothetical example in my earlier reply for how the latter works (just use
an association instead of an array). The former isn't relevant here (array
indexes aren't useful as patterns anyway), but it works like this:

  % local -A assoc=( 'a*' val1 '*a' val2 )
  % print ${assoc[(k)abc]}
  val1
  % print ${assoc[(k)cba]}
  val2

If the (k) expansion flag were made to work on indexed arrays it would
definitely not need to do any pattern matching.

dana



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