From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5677 invoked from network); 28 May 2006 18:17:47 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.2 (2006-05-25) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.2 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 28 May 2006 18:17:47 -0000 Received: (qmail 14313 invoked from network); 28 May 2006 18:17:39 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 28 May 2006 18:17:39 -0000 Received: (qmail 22799 invoked by alias); 28 May 2006 18:17:31 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10327 Received: (qmail 22790 invoked from network); 28 May 2006 18:17:30 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 28 May 2006 18:17:30 -0000 Received: (qmail 13163 invoked from network); 28 May 2006 18:17:30 -0000 Received: from vms040pub.verizon.net (206.46.252.40) by a.mx.sunsite.dk with SMTP; 28 May 2006 18:17:29 -0000 Received: from torch.brasslantern.com ([71.116.105.50]) by vms040.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0IZZ00DPEMT2WUM2@vms040.mailsrvcs.net> for zsh-users@sunsite.dk; Sun, 28 May 2006 13:17:27 -0500 (CDT) Received: from torch.brasslantern.com (localhost.localdomain [127.0.0.1]) by torch.brasslantern.com (8.13.1/8.13.1) with ESMTP id k4SIHPca029226 for ; Sun, 28 May 2006 11:17:25 -0700 Received: (from schaefer@localhost) by torch.brasslantern.com (8.13.1/8.13.1/Submit) id k4SIHOHr029225 for zsh-users@sunsite.dk; Sun, 28 May 2006 11:17:24 -0700 Date: Sun, 28 May 2006 11:17:24 -0700 From: Bart Schaefer Subject: Re: Keying arrays to names: is there an array of arrays? In-reply-to: To: ZSH Users Message-id: <060528111724.ZM29224@torch.brasslantern.com> MIME-version: 1.0 X-Mailer: OpenZMail Classic (0.9.2 24April2005) Content-type: text/plain; charset=us-ascii References: <44771E3E.9070102@ulpmm.u-strasbg.fr> <200605261540.k4QFeReG007573@news01.csr.com> <060527151044.ZM25448@torch.brasslantern.com> Comments: In reply to "Johann 'Myrkraverk' Oskarsson" "Re: Keying arrays to names: is there an array of arrays?" (May 28, 2:34am) On May 28, 2:34am, Johann 'Myrkraverk' Oskarsson wrote: > > The following version also works with IFS="" (I guess it will work > with IFS equal to something sensible too). > > mapassign() { > local h=$1 k=$2 > shift 2 > set -- ${(j: :q)*} > typeset -gA $h > typeset -g $h\[$k\]="$*" > } A better approach might be: mapassign() { emulate -L zsh local h=$1 k=$2 IFS=$' \t\n\0' shift 2 set -- ${(q)*} typeset -gA $h typeset -g $h\[$k\]="$*" } > Same with this one: > > mapread() { > set -- $1\[$2\] > reply=( ${(s: :Q)${(z)${(P)1}}} ) > } That's actually incorrect. The (z) option is already splitting the value; you shouldn't need or want to split it again with (s: :). If the setting of IFS is preventing (z) from working properly, that's probably a bug, but in any case the workaround is to make IFS local. mapread() { emulate -L zsh local IFS=$' \t\n\0' set -- $1\[$2\] reply=( ${(Q)${(z)${(P)1}}} ) } If you're going to use these functions for hash access anyway, then you might as well also use ${(q)2} instead of $2 in both of them, to avoid issues with non-alphanumeric keys.