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

Re: Reverse the order of an array?



 --- Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote: 
> 
> Hmm, I should have thought of that.
> 
> 	eval osvers\=\( \"\$osvers\[{$#osvers..1}\]\" \)
> 

Not very intuitive that is it.

I recently wanted to loop over an array's elements in reverse and
though I could do it with a for loop counting the indices backwards I
did think that there ought to be a better way.

Allowing array slices to go backwards, is a possibility though I'd not
be suprised if implementing it caused other things to break. The
easiest might be a parameter expension flag (r and R are gone so we'd
need a letter. ^ perhaps as we used that for the reversed prompt
state). Does anyone else have any views on whether we should add
something for this and if so how?

Oliver

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com



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