in reply to Get every nth element

#For every $n element in @List grep {not ++$i % $n} @List;
This is kind of cool. You are right, grep is probably under used. I also like the use of pre-increment which will, as a bit of perl magic, initialize $i for you. (actually so will post increment but as it turns out, aside from the offset issue here, preincrement is generally more efficiant for the compiler).

Replies are listed 'Best First'.
RE: RE: Get every nth element
by mdillon (Priest) on May 08, 2000 at 20:01 UTC
    the pre-increment also serves to shift the effective array indexing from zero-based to one-based, allowing the modulus arithmetic to return 0 on the correct indices. if you used postincrement, then the modulus would be evaluated before the increment, causing the wrong elements to be chosen.