zsh-users
 help / color / mirror / code / Atom feed
From: Felix Herrmann <fhml@herrmann-koenigsberg.de>
To: zsh-users@zsh.org
Subject: Re: Filtering an array
Date: Fri, 24 Feb 2012 11:25:11 +0100 (CET)	[thread overview]
Message-ID: <20120224102511.6ED931A8532@localhost.localdomain> (raw)
In-Reply-To: <CABZhJg9QFx89rSrRhaN8UPNpbfsKHGQbAVJhzYGT+05PYeRR=g@mail.gmail.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1193 bytes --]

Hi :)

On Fri, 24 Feb 2012 08:11:29 +0100, Jesper Nygårds wrote:
> The idea is to find all files that contain all of the strings given. I
> first find all files containing the first argument, then shift away
> the first argument and filter the array of file names with each of the
> remaining arguments.
> 
> However, for some reason only the first round of filtering (i.e. using
> the second argument) is happening[...].

I'm no expert at all at zsh-scripts but I think the problem is that
myfiles isn't an array anymore after the first iteration. I changed your
code to the following:

findfiles() {
    local myfiles myarg
    myfiles=( **/*$1* )
    shift
    for myarg; do
        myfiles=(${(M)myfiles:#*$myarg*})
    done
    print $myfiles
}

There are two little differences here. First of all, I didn't write '$@'
in the for-line. If you don't give an 'in x', for iterates over the
remaining arguments.

The second difference - and the more important one - is, that I put ()
around the rhs of the myfiles-assignment, to make sure to assign an
array to the variable myfiles. I think that was the catch. After this
modification, your script works fine :)

Greetings,
Felix Herrmann.


  reply	other threads:[~2012-02-24 11:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-24  7:11 Jesper Nygårds
2012-02-24 10:25 ` Felix Herrmann [this message]
2012-02-28  7:24 ` S. Cowles
2012-02-29 13:43   ` Jesper Nygårds

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=20120224102511.6ED931A8532@localhost.localdomain \
    --to=fhml@herrmann-koenigsberg.de \
    --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).