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;
|
|---|
| 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 |