From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26646 invoked by alias); 2 Nov 2015 03:08:50 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20870 Received: (qmail 25833 invoked from network); 2 Nov 2015 03:08:47 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern_com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=VTX+4MB39uUGXL1TRIaZxz2vRWgxmZnA9mzEYCIZtSE=; b=cBNnUC28ViO0lnhCHwSkujkx6oJZEfUw0GAWbtN9Cv7YSN6doVNd+OEnR0qosTSxlC riFy2wWdHbYmzknvGKQwMBf9ncVDqfNbfXQDNu2OtJwalz/8NjYXUblKv42Jg9jr07Du Zl/3CynPh/d21VTn0Fv+Cy0qhCRQNUxELbP+/z9BZL5iaqSgTHVmkqSnFr5Qd05t05vQ ZsjawqDlYefbXdXRqj7S5rTe5Xbye/Ih0nvJ9114Av9PfiGpYyz11tqQLoETGxgGDPJq GhmqxJ0JrP4SFcsb552Sut8yZSAKgiwiFD80bNXf4EJ29sIOu1BOIZmCeBiF0PJOA97D MmBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=VTX+4MB39uUGXL1TRIaZxz2vRWgxmZnA9mzEYCIZtSE=; b=MgHundI5fLiJBMtWDRpCs7KaANdT3NmFOj6XRi1/tu6LKsOSIlonl2etbFHgqa4NQC vbIyZO+2Vyjm5YgUgYnS1a34knLnAeg0ERnUSGX3cJYux2Ii7LEFuVayqLpi80rheHJv 8p9Ej9J9r5lHEDto32fxLMEn6uUwv4RwOl+t8O9pzrZpEsepItCKrmcNQeS4kyTZiWkp eRGvnk8wNFr46ti/Lj/HFJ3q6mARUBxeHfwSVPl38RP74O5AKPK+ouCcQ8RmP4BFHN5Z tIQ/InHrywAEbr5/fiq81KZJLO46N2MZYxbioSmtFeW06I5qvaseLM39YzBvX4UZGfsx ykkA== X-Gm-Message-State: ALoCoQkPo7+sKz0OmpKzxwzCHt3WhZIVtZunzg2a5mkJ0hKJ8hgJf0WUYAgW1kCSNK/iRLPk3joO X-Received: by 10.202.199.142 with SMTP id x136mr12411099oif.121.1446433724962; Sun, 01 Nov 2015 19:08:44 -0800 (PST) From: Bart Schaefer Message-Id: <151101190842.ZM16752@torch.brasslantern.com> Date: Sun, 1 Nov 2015 19:08:42 -0800 In-Reply-To: <5636B333.8060300@eastlink.ca> Comments: In reply to Ray Andrews "Re: easy calling of associative array?" (Nov 1, 4:49pm) References: <56369C7B.2030604@eastlink.ca> <1237641446422150@web6m.yandex.ru> <5636B333.8060300@eastlink.ca> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: easy calling of associative array? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Nov 1, 4:49pm, Ray Andrews wrote: } Subject: Re: easy calling of associative array? } } On 11/01/2015 03:55 PM, ZyX wrote: } > } > There is ${(P)} for indirect referencing: } } I can't get it to work with associative arrays tho. Yeah, it's a bit weird with associative arrays because everything is passed by value. ${(P)ref} is ${(vP)ref} and thus ${${(P)ref}[idx]} doesn't get what you want, and ${(P)ref[idx]} is ${(P)${ref[idx]}} which also isn't what you want. So you have to get a little arcane: ${(P)${:-${ref}[idx]}}. - ${ref} is the name of the assocative array. - ${ref}[idx] is therefore a string that has the same format as the array lookup you want to perform. - ${:-${ref}[idx]} substitutes that string into a parameter expansion. - ${(P)${:-${ref}[idx]}} then treats that substitution as another parameter expansion, and you end up where you wanted to be. This is admittedly not ideal, but until we embark on a significant rewrite of parameter expansion, we're stuck maneuvering values into the right places at the right times.