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

Re: DWIM interface to date args; reverse array



On Wed, 15 Nov 2017 15:37:44 +0100
Emanuel Berg <moasen@xxxxxxxx> wrote:
> time-from () {

I'd suggest if the question is really "how do I reverse an array?", it's
best not to add distracting material which is simply hiding your
question.  The more obvious the question is, the more people will bother
thinking about it.

On the other hand, if you were asking "how do I write this function
better?" then the context would certainly be important.  But I don't
see that question here.

>     # instead of doing this one could reverse the original data array
>     # I Googled "zsh reverse array" and found ${(Oa)array}
>     # but seems to only work when I echo it,
>     # not assign it to another array

You haven't shown what you expected to work that didn't, so I can't
really answer what you actually said, so I'm reduced to guesswork.
Please show (just) what you think should work and doesn't.  (Or, to
put it another way, the answer to what you just said is "yes, it does
actually work", which I'm guessing isn't going to help you much...)

Try

array=(${(Oa)array})

remembering the outer parenthesis, otherwise you are assigning a scalar.

pws



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