From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: "Jesper Nygårds" <jesper.nygards@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Filtering array on index
Date: Tue, 23 Jul 2019 09:42:20 +0200 [thread overview]
Message-ID: <CAKc7PVCHY-EjwtkYRye4peepc_kOnKyvoMyZBVEf7eK3+W128Q@mail.gmail.com> (raw)
In-Reply-To: <CAKc7PVBfQ_Z-zOxbS_6Vv8SZGDYOGn-nEyWTAvzAr3eyvdHN8A@mail.gmail.com>
On Tue, 23 Jul 2019 at 05:38, Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> On Thu, 25 Oct 2018 at 13:30, Jesper Nygårds <jesper.nygards@gmail.com> 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
next prev parent reply other threads:[~2019-07-23 7:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-25 11:29 Jesper Nygårds
2018-10-25 18:17 ` Mikael Magnusson
2018-10-25 18:55 ` Jesper Nygårds
2018-10-25 19:42 ` Daniel Shahaf
2018-10-25 20:21 ` Bart Schaefer
2018-10-25 20:42 ` dana
2018-10-26 4:14 ` Jesper Nygårds
2018-10-26 7:59 ` Jesper Nygårds
2018-10-26 8:21 ` dana
2018-10-26 9:28 ` Jesper Nygårds
2018-10-28 2:45 ` Bart Schaefer
2019-07-23 3:38 ` Sebastian Gniazdowski
2019-07-23 7:42 ` Sebastian Gniazdowski [this message]
2019-07-23 8:03 ` Sebastian Gniazdowski
2019-09-08 8:59 ` Sebastian Gniazdowski
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=CAKc7PVCHY-EjwtkYRye4peepc_kOnKyvoMyZBVEf7eK3+W128Q@mail.gmail.com \
--to=sgniazdowski@gmail.com \
--cc=jesper.nygards@gmail.com \
--cc=zsh-users@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).