From: Mikael Magnusson <mikachu@gmail.com>
To: Mikael Magnusson <mikachu@gmail.com>, zsh-workers@zsh.org
Subject: Re: Array as parameter
Date: Wed, 2 Nov 2011 13:13:19 +0100 [thread overview]
Message-ID: <CAHYJk3Sm6CKpfs6EAfwrao2WZbJYVGXG=QjDbRMq3DSVdBTYEQ@mail.gmail.com> (raw)
In-Reply-To: <20111102120649.GB6375@yahoo.fr>
On 2 November 2011 13:06, Stephane Chazelas <stephane_chazelas@yahoo.fr> wrote:
> 2011-11-02 11:14:38 +0100, Mikael Magnusson:
>> On 2 November 2011 10:10, Stephane CHAZELAS <stephane_chazelas@yahoo.fr> 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:
> ~/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
next prev parent reply other threads:[~2011-11-02 12:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20111102033545.GI28043@solfire>
[not found] ` <CAHSx_SsGPHWkGfspXKo39oZ6G3Rd+H-8_2PAuixHmW94d4VCEg__34702.1825182766$1320210589$gmane$org@mail.gmail.com>
2011-11-02 9:10 ` Stephane CHAZELAS
2011-11-02 10:14 ` Mikael Magnusson
2011-11-02 12:06 ` Stephane Chazelas
2011-11-02 12:13 ` Mikael Magnusson [this message]
2011-11-02 12:15 ` Mikael Magnusson
[not found] <20111102033545.GI28043__714.249446946447$1320205564$gmane$org@solfire>
2011-11-02 9:04 ` Stephane CHAZELAS
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHYJk3Sm6CKpfs6EAfwrao2WZbJYVGXG=QjDbRMq3DSVdBTYEQ@mail.gmail.com' \
--to=mikachu@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).