in reply to Elegantly Selecting Every 3rd Element in an Array.

Give this a try:

for ($i=0; $i < @a; $i += 3) { print "$a[$i] "; }

conv

Replies are listed 'Best First'.
Re: Re: Elegantly Selecting Every 3rd Element in an Array.
by jlongino (Parson) on Sep 29, 2001 at 03:56 UTC
    Maybe I did something wrong, but when I run your example I get "las saturday is" and not "every third element".

    "Make everything as simple as possible, but not simpler." -- Albert Einstein

      I noticed that too.... easy fix though, replace $i=0 with $i=2. As written, the code gives you every third word, but it doesn't start on the "correct" one.

      -Blake