Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Keying arrays to names: is there an array of arrays?
- X-seq: zsh-users 10314
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Keying arrays to names: is there an array of arrays?
- Date: Fri, 26 May 2006 16:40:27 +0100
- In-reply-to: <44771E3E.9070102@xxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <m33bewj29n.fsf@xxxxxxxxxxxxxxxxxx> <44771E3E.9070102@xxxxxxxxxxxxxxxxxx>
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@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