Perl Programming | ||
---|---|---|
What does Perl look like? | ||
# Accept a number from the user print "maximum:"; $maximum = <STDIN>; # Make an array of numbers @numbers = (2..$maximum); # Iterate through that array while ($prime = shift @numbers) { # Print the next prime print "$prime\n"; # Remove multiples of that prime @numbers = grep {$_ % $prime} @numbers; } |
||
Previous | http://stuff.mit.edu/iap/perl/ | Next |