in reply to Re^3: Primes. Again.
in thread Primes. Again.

I, for the life of me, could not grasp the "length $_" concept (what it was testing for each entry), so we re-wrote it in a way that worked better for our comprehension.

use strict; use warnings; my @prime = (2); my $not_prime; for my $i(3..100){ $not_prime=0; for(@prime){ next if int($i/$_)!=($i/$_); $not_prime=1; } push @prime, $i if $not_prime!=1; } print join "\n", @prime;


Thanks again for your help! (The next, last, and conditional-if's that you inadvertantly taught me are VERY welcomed pieces of information.)

Replies are listed 'Best First'.
Re^5: Primes. Again.
by GrandFather (Saint) on Apr 26, 2006 at 21:06 UTC

    length returns the length (number of characters) in a string. Because you were setting the string to empty I used length to test for that condition and skip the empty string.

    Others have provided better solutions. I was more interested in keeping to the essential structure of your code and using that as a springboard for teaching a little Perl. I seem to have achieved that. :)


    DWIM is Perl's answer to Gödel