zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-users@sunsite.dk
Subject: Re: print entire array *with* subscript?
Date: Fri, 10 Feb 2006 18:03:54 +0000	[thread overview]
Message-ID: <EXCHANGE03XHbQbilav0000bbe8@exchange03.csr.com> (raw)
In-Reply-To: <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@csr.com>                  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


  reply	other threads:[~2006-02-10 18:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200602101756.59858.arvidjaar@mail.ru>
2006-02-10 17:50 ` Jean-Rene David
2006-02-10 18:03   ` Peter Stephenson [this message]
2006-02-11  4:15     ` Justin M Wozniak
2006-02-11  5:20       ` Bart Schaefer
2006-02-09 19:40 Jean-Rene David

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EXCHANGE03XHbQbilav0000bbe8@exchange03.csr.com \
    --to=pws@csr.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).