zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-users@sunsite.dk
Subject: Re: Keying arrays to names: is there an array of arrays?
Date: Fri, 26 May 2006 16:40:27 +0100	[thread overview]
Message-ID: <200605261540.k4QFeReG007573@news01.csr.com> (raw)
In-Reply-To: <44771E3E.9070102@ulpmm.u-strasbg.fr>

Marc Chantreux wrote:
> > Second, I'd like to ask if it's possible to key an array to a name?
>
> % typeset -A a
> % a[a]='those are values'
> % print -l ${(s: :)a[a]}
> those
> are
> values

This reminds me I was going to post a general solution along the same
lines which deals with embeded spaces etc.:

% array=(one 'two three' '"four five six"')
% typeset -A hash
% array=(${(q)array})
% hash[key]="${array}"
% array=(${(Q)${(z)hash[key]}})
% print -r $array
one
two three
"four five six"

I couldn't work out how to do the encoding in a single step,
since "${(q)array}" and all the variants of it I could think of quote
the spaces that are to be used as separators.

--
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-05-26 15:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-26 14:20 Johann 'Myrkraverk' Oskarsson
2006-05-26 15:26 ` Marc Chantreux
2006-05-26 15:40   ` Peter Stephenson [this message]
2006-05-26 15:58     ` Peter Stephenson
2006-05-27 19:09     ` Johann 'Myrkraverk' Oskarsson
2006-05-27 22:10       ` Bart Schaefer
2006-05-28  2:34         ` Johann 'Myrkraverk' Oskarsson
2006-05-28 18:17           ` Bart Schaefer
2006-05-28 21:32             ` Johann 'Myrkraverk' Oskarsson

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=200605261540.k4QFeReG007573@news01.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).