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

Re: A way to apply function to each element of an array



On Thu, Aug 29, 2019 at 2:51 AM Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
>
> myarr=( "${(@)${myarr[@]/(#m)*/$(( msfunc(${(q)MATCH}) ))$REPLY}/(#s)0/}" )

I usually use ${foo+} to expand foo for its side effects and to ignore
the substituted value.

    myarr=( "${(@)${myarr[@]/(#m)*/${$((msfunc(${(q)MATCH})))+}$REPLY}}" )

This way you can discard the substituted value without knowing what it is.

Roman.



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