Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: easy calling of associative array?
- X-seq: zsh-users 20870
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: easy calling of associative array?
- Date: Sun, 1 Nov 2015 19:08:42 -0800
- 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==
- In-reply-to: <5636B333.8060300@eastlink.ca>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <56369C7B.2030604@eastlink.ca> <1237641446422150@web6m.yandex.ru> <5636B333.8060300@eastlink.ca>
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author