Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: print entire array *with* subscript?
- X-seq: zsh-users 9903
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: print entire array *with* subscript?
- Date: Fri, 10 Feb 2006 18:03:54 +0000
- In-reply-to: <20060210175012.GA10021@princo>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20060210175012.GA10021@princo>
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...
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
Messages sorted by:
Reverse Date,
Date,
Thread,
Author