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

Re: e:: with an array ?



On Aug 22, 10:45pm, Marc Chantreux wrote:
} 
} print -l *(e:true:)
} 
} works but 
} 
} x=(*); print -l ${(e:true:)x}
} 
} is an error.

In general there's no correlation between glob qualifiers and parameter
expansion flags, so you shouldn't expect that.  E.g. ${(U)x} means to
convert $x to uppercase, but *(U) means to match files owned by the
current effective user ID.

One could argue that given (N) to turn on NULL_GLOB and (D) to turn
on GLOB_DOTS, there should also be a way to turn on NO_NOMATCH so that
one could force an (e::) qualifier to be applied to nonexistent files.
However, NO_NOMATCH normally means that the entire pattern _including_
qualifiers must be preserved unchanged on a match failure, so turning
it off within the qualifiers is a logical quandary.  Note also that
even with NO_NOMATCH, *(e:false:) fails with "no such file."

} I haven't found an alternative in the doc so i wonder again
} (http://www.zsh.org/mla/users//2006/msg00193.html) if there is a kinda
} perl grep :-)

If you mean
  grep { func } @x
as in
  map { if (func) { $_ } else { () } } @x
then no, there is no direct zsh equivalent, except in the special case
where func is the zsh equivalent of m/pattern/.

With extendedglob set, zsh does have ${x/(#b)(*)/$(func $match)},
which can be made to behave mostly like perl map.  If func is limited
to things that can be expressed as parameter expansion operations, you
can change $(...) to ${...}, save a fork, and annoy Matthias Kopferman.



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