From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5956 invoked by alias); 2 Nov 2015 19:02:15 -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: 20876 Received: (qmail 26287 invoked from network); 2 Nov 2015 19:02:12 -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 autolearn=ham autolearn_force=no version=3.4.0 X-Authority-Analysis: v=2.1 cv=T/C1EZ6Q c=1 sm=1 tr=0 a=hFxs0f5JAArYXmzDxhrHQA==:117 a=hFxs0f5JAArYXmzDxhrHQA==:17 a=N659UExz7-8A:10 a=a-7xE68ScYwpfFLp5x4A:9 a=pILNOxqGKmIA:10 Message-id: <5637AC27.8010007@eastlink.ca> Date: Mon, 02 Nov 2015 10:32:07 -0800 From: Ray Andrews User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-version: 1.0 To: zsh-users@zsh.org Subject: Re: easy calling of associative array? References: <56369C7B.2030604@eastlink.ca> <1237641446422150@web6m.yandex.ru> <5636B333.8060300@eastlink.ca> <151101190842.ZM16752@torch.brasslantern.com> <5636D99F.2030807@eastlink.ca> <151101225100.ZM16882@torch.brasslantern.com> <563784B5.3040901@eastlink.ca> <151102082808.ZM17640@torch.brasslantern.com> In-reply-to: <151102082808.ZM17640@torch.brasslantern.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit On 11/02/2015 08:28 AM, Bart Schaefer wrote: > } #$3=${(P)${:-${1}[$2]}} #nothing works Pardon, that was an obvious mistake. Too much thrashing around with 'eval'. > Same assignment-syntax problem. > > set_v () { > typeset -g "${1}[$2]=$3" # quotes so [ ] isn't globbing > } > > Here you don't need the (P) indirection because ${1} and $2 are both > expanded before being passed to typeset, so you already extracted the > name that was passed in $1. ... and that's nicely readable too--the sort of syntax that seems intuitive, as I mentioned. I won't say this is all clear in my mind, but it's at least tractable. One further question: I've never seen 'typeset' used to refer to anything but a simple variable. I note that the above does not work without the 'typeset -g' so what does that accomplish? I've never thought of the positional parameters and being typeset-able. I get the feeling it is a future problem solver. > > Also note I'm ignoring all possible error checking, e.g. if $1 is not > an identifier (in the worst case, contains an "="), things go badly. Sure, it's naive at this point. I don't yet think past that. > I'm not exactly sure what you're wanting as either output or exit > status here, but except that I'd recommend [[ ]] instead of [ ] as > the test syntax, what you wrote for "this works" is sensible. Ok. I don't pay enough attention to the difference. BTW, as a point of list etiquette: Responding to most posts I let my lines wrap but resonding to yours, which seem to alway have fixed line width, I try to match that style, but looking at the returned posts from the list, they sometimes sproing badly. Should I try to keep to your width, or just let lines wrap? >