in reply to Primes. Again.
Your main issue was that you were blanking out non-primes, but then using them in calculations. The empty string part of the error message was a clue. The line number was another. You may like this cleaned up version of you code that fixes that problem, suppresses the blank lines that your original code would have produced, and reduces the nesting somewhat.
use strict; use warnings; my @prime = (2); for my $i(3..100){ push @prime, $i; for(@prime){ next if ! length $_; next if int($i/$_)!=($i/$_) or $i==$_; $_=~s/$i// for @prime; } } print join "\n", grep {length $_} @prime;
Prints:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Primes. Again.
by Andrew_Levenson (Hermit) on Apr 26, 2006 at 03:24 UTC | |
by GrandFather (Saint) on Apr 26, 2006 at 03:36 UTC | |
by Andrew_Levenson (Hermit) on Apr 26, 2006 at 15:47 UTC | |
by GrandFather (Saint) on Apr 26, 2006 at 21:06 UTC |