|We don't bite newbies here... much|
Re: Find Element of array but use the next Elementby davido (Archbishop)
|on Jun 14, 2012 at 16:01 UTC||Need Help??|
List::MoreUtils is fun.
Updated: Allowed for the possibility of 'Oracle' appearing in an 'even' numbered element. At first it seemed like a given that it appears in 'odd' elements, but that's never stated in the question, so it's safer to assume it could appear anywhere in the array. Also allowed for the possibility that there is no element following an instance of 'Oracle'.
Just for the fun of it, a couple more:
Personally, I think the first 'index' implementation reads the cleanest because it explicitly tells the reader that the output is indices. The first 'grep' solution is a close second, since it eliminates the need for the defined test.
Of course there's also the simple approach:
It's hard to beat the good old fashioned while loop.