primes/primes.perl.pl

32 lines
471 B
Perl
Executable File

#!/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";}
}