Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Filtering array on index
- X-seq: zsh-users 24089
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Jesper Nygårds <jesper.nygards@xxxxxxxxx>
- Subject: Re: Filtering array on index
- Date: Tue, 23 Jul 2019 09:42:20 +0200
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=I8UgsgpN0mwclT+9i3E9HtN5WlusFtQubIpb+eSl4Fs=; b=nahowUpL7yB7Kk9pQG+OzBcfMZsWAIA4xhtLMJ8E6d4nNmQLaI/Jm7n7dr3eeedeUT mF0/xuvER7N8dRa3WffkzqaEXhws2CPrEPCW8bO5yY8iFFLcyV4tPKS/AiakdIuuR4Y3 vjX8GYgN3cyF7bo1IWmmyedeXkPm8bArq4Ma4c0UZ5pmO8J8xt2E8/pBOBu70a9gFZlk bFYYgwXlWcz7ODwLkEB4qvDK+foLv8Pyg7Rf1QU/WkXiAo0xFpquX21z3wXZ8onqBkai 6igLi+B+h2kaf/mOhcgWE+AXVgaUi2sBHPi4nSHiFT0npz/pC6cKiJ2NdTIthHL9byuZ yCHA==
- In-reply-to: <CAKc7PVBfQ_Z-zOxbS_6Vv8SZGDYOGn-nEyWTAvzAr3eyvdHN8A@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CABZhJg80vQuMHGKABkzR1bdtt89Akpkfd8kWOV83N-qvqioaXw@mail.gmail.com> <CAKc7PVBfQ_Z-zOxbS_6Vv8SZGDYOGn-nEyWTAvzAr3eyvdHN8A@mail.gmail.com>
On Tue, 23 Jul 2019 at 05:38, Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
>
> On Thu, 25 Oct 2018 at 13:30, Jesper Nygårds <jesper.nygards@xxxxxxxxx> wrote:
> > myarr=(-v filter1 -v filter2)
>
> I've recently had this problem. One other way to do it:
>
> ~ idx=0; olen=$#a+1; a=( ${a[@]/(#m)*/$a[$(( ++idx % 2 ? olen : idx ))]} )
Turns out the expression can be simpler because the math mode within
array's index is implicit, so:
idx=0; olen=$#a+1; a=( ${a[@]/(#m)*/$a[ ++idx % 2 ? olen : idx ]} )
I've also tried to construct an ::= assignment version. A safe.
different output variable version is:
b=(); idx=0; olen=$#a+1; : ${a[@]/(#m)*/${b[++idx]::=${a[idx % 2 ?
olen : idx]}}}
However, this yields 8 empty elements (for the a=(-v filter1 -v filter2 ))::
% print -rl -- "${(q)b[@]}"
''
''
...
prepending $idx after ::= yields following output:
''
1
''
3
''
5
''
7
I wonder what's going on? The code looks OK. Maybe it's a bug?
--
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org
Messages sorted by:
Reverse Date,
Date,
Thread,
Author