You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

31 lines
471 B

#!/usr/bin/perl
# PERL version of a Prime Number Finder
# haplo@mindstab.net
if(@ARGV > 0)
{
$max = $ARGV[0];
} else
{
print "primes.pl <MAX NUM>\n";
exit;
}
if($max < 1)
{
print "Invalid MAX NUM\n";
exit;
}
for($counter =3; $counter < $max; $counter +=2)
{
$max_test = sqrt($counter);
$isPrime = 1;
for($tester=3; $tester <= $max_test; $tester+=2) {
if(!($counter % $tester)) {
$isPrime = 0;
last;
}
}
if($isPrime == 1) {print "$counter\n";}
}