in reply to Re^3: Answer: Easy way to list prime numbers 1 to 100
in thread Easy way to list prime numbers 1 to 100

Semantically odd I'd agree with, though that's almost par for the course in Perl :)

That said, your alternative is possible worse, in as much as you are (repeatedly) calling do in a void context, so unless it is context aware, you're discarding it's return values.

Ignoring that the code doesn't make much sense, I'd go for

@odds = grep{ $_ % 2 } 2 .. 100;

with those small hardcoded limits, or if they were much larger or unknown:

$_ % 2 and push @odds, $_ for 2 .. $LIMIT;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^5: Answer: Easy way to list prime numbers 1 to 100
by gellyfish (Monsignor) on May 23, 2006 at 10:25 UTC

    Totally in agreement, I got hung up on the push thing and had censored grep from the front of my mind for some reason.

    I'm not so sure about the inefficiency or otherwise of the idiom though, whilst it's pretty pointless here admittedly, we have have had do {} while and do {} until basically forever and documented as upside down loops, and discarding the (implicit) return values is something we do all the time with subroutines and so forth.

    /J\