Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Zsh functionality similar to Perl 'map'?



On Nov 20, 11:03am, Benjamin R. Haskell wrote:
}
} Ideally, it'd end up as something like:
} 
} diff -ur =({do-something1,do-something2} | filter)
} or
} diff -ur =(filter {file1,file2})
} 
} ...and, yes, I know that's a *huge* stretch.  And, maybe my Perl bias for 
} map'ping everything is showing, but still, figured I'd ask.

Have a look at http://www.zsh.org/mla/users/2006/msg00832.html

There's a trick to replacing $(...) with =(...).  If I write

    setopt extendedglob
    x=(a b c)
    cat ${x/(#b)(*)/=(echo foo $match)}

I get 

    foo match
    foo match
    foo match

because $match is being expanded before it has been set by the (#b)
operator.  It's entirely possible this is a bug.  The workaround is to
single-quote the contents as in =('...'):

    cat ${x/(#b)(*)/=('echo foo $match')}

    foo a
    foo b
    foo c

I haven't delved into whether this is explainable with the normal
order-of-expansion rules.  Anyway, throwing this all together in a
very non-obvious way, you can write:

diff -ur ${${(A)reply::={file1,file2}}/(#b)(*)/=('filter $match')}

Where the parts you care about manipulating are names in {file1,file2}
and of course the filter.  "reply" is used as a dummy array variable
for the ::= assigment, pick any name that won't clobber something you
are interested in.  Quoting of spaces or other special characters in
the file names may be a fairly unpleasant exercise.



Messages sorted by: Reverse Date, Date, Thread, Author