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

Re: print entire array *with* subscript?



In your solution, what is the point of (r) ?

-- 
Justin Michael Joseph Wozniak

On Fri, 10 Feb 2006, Peter Stephenson wrote:

> Jean-Rene David wrote:
> > It would be nice to be able to do this:
> >
> > print ${(k)files}
> > 1 foo.h 2 foo.c 3 bar.h 4 bar.c
> >
> > instead of:
> >
> > for f in {1..$#files}; do
> >   print $f ${files[$f]};
> > done
> >
> > Not a big deal. Just asking because that's what I
> > thought the documentation meant.
>
> I think the documentation for the (k) flag is (for once) reasonably
> clear and accurate:
>
>        k      If  name  refers  to  an  associative array, substitute the keys
>               (element names) rather than the values of  the  elements.   Used
>               with  subscripts  (including  ordinary arrays), force indices or
>               keys to be substituted even if the subscript form refers to val-
>               ues.   However,  this  flag  may  not be combined with subscript
>               ranges.
>
> This means you can use it with normal arrays, but only with individual
> indices.  So:
>
> % print ${(k)files[(r)foo.c]}
> 2
>
> but it doesn't work with a subscript nor with a range nor with the *
> and @ subscripts (which are special ranges).
>
> That doesn't mean this is convenient...
>
>



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