From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26822 invoked by alias); 2 Nov 2011 12:15:41 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29888 Received: (qmail 19608 invoked from network); 2 Nov 2011 12:15:40 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW, T_DKIM_INVALID,T_TO_NO_BRKTS_FREEMAIL autolearn=no version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.220.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=LPpP+nvZmfDvyl6mfEtArW9HtT2OCJ3jeZGMVDlUvME=; b=jd3SmbpjXR8ySFqqBkpsZ+D/ILVF8k3gaMw1H687bOMISwvtYpJDFCNqcGlxJcYu/Z UvzCrmA4n8WVnR1N5mH0dW3jW8+Z8U7walM0c0cdVGGNCakPgg1f3ctdIXHQzl304AOc yRNlp4+x+QJnLhAHPFelojVuZkTz4igr9tfiM= MIME-Version: 1.0 In-Reply-To: References: <20111102033545.GI28043@solfire> <20111102120649.GB6375@yahoo.fr> Date: Wed, 2 Nov 2011 13:15:35 +0100 Message-ID: Subject: Re: Array as parameter From: Mikael Magnusson To: zsh-workers@zsh.org Content-Type: text/plain; charset=UTF-8 On 2 November 2011 13:13, Mikael Magnusson wrote: > On 2 November 2011 13:06, Stephane Chazelas wrote: >> 2011-11-02 11:14:38 +0100, Mikael Magnusson: >>> On 2 November 2011 10:10, Stephane CHAZELAS wrote: >>> > 2011-11-1, 22:00(-07), Wayne Davison: >>> >> However, if you need to be able to keep the array >>> >> parameter separate from other parameters, you could instead refer to the >>> >> variable whose name you passed in using ${(P)1} in your function in place >>> >> of the $1. >>> > >>> > Except that it doesn't work for arrays. You'd need to use eval >>> > here. >>> >>> (P) works perfectly fine with arrays. >> [...] >> >> Indeed, though it seems you have to write it as "${${(@P)1}[@]}", I'm not too sure why. > > You need to specify @ at every nesting level that's inside double > quotes to prevent scalar joining. At the ${(P)b[@]} level, if that was > an implied question, the subscript is applied first: [apparently some keycombo i just pressed sends the message in gmail, i wonder what it was] % zsh -c 'a=("" "a b" c d); b=(b a); print -l "${(@P)b[2]}"' a b c d % zsh -c 'a=("" "a b" c d); b=(b a); print -l "${(@P)b[1]}"' b a >> ~/install/cvs/pixz$ zsh -c 'a=("" "a b" c d); b=a; print -l "${${(P)b}[@]}"' >> a b c d >> ~/install/cvs/pixz$ zsh -c 'a=("" "a b" c d); b=a; print -l "${${(@P)b}[@]}"' >> >> a b >> c >> d > > But this is shorter, > % zsh -c 'a=("" "a b" c d); b=a; print -l "${(@P)b}"' > > a b > c > d -- Mikael Magnusson