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

Re: Keying arrays to names: is there an array of arrays?



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