Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: Primes. Again.

by Andrew_Levenson (Hermit)
on Apr 26, 2006 at 15:47 UTC ( [id://545813]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://545813]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-24 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found