in reply to Mock my code!

I made a number of changes.
  1. Got rid of the primes file. Unless you're planning on working with substantially more than 10,000 primes, this way is just as fast, or faster. (You're not loading primes you won't need...)
  2. Unless you have a reason for only putting 10,000 primes in a file, I'd put everything in the same file. It makes working with them later a little easier.
Of course, the question arises of why you're even doing it this way. If you already have the list of primes, why not just start with lowrange and go to the hirange of the primes. If you're trying to determine further primes, you're going to find non-primes because you're not increasing your list of primes. (What if your list of primes ends at the 10,000th prime, but your range includes the 10,001st prime squared ...) This way, you guarantee to find only primes.
#!/usr/local/bin/perl -w use strict; ###################################################################### +########## my $resultFile = "results.txt"; my $lowrange = 0; my $hirange = 0; ###################################################################### +########## print "Welcome to the prime number program.\n"; print "This program will tell you every prime number within a certain +range.\n"; print "Please enter the lower range now: "; chomp($lowrange = <STDIN>); die "\nThe low must be a positive integer\n" if ($lowrange && $lowrange =~ /\D/); print "\nHow high should the program search for primes? "; chomp($hirange = <STDIN>); die "\nThe high must be a positive integer\n" if ($hirange && $hirange =~ /\D/); die "\nThe high must be greater than or equal to the low\n" if ($hirange < $lowrange); print "Now listing the range of all primes between $lowrange and $hira +nge. \n"; print "Please wait.\n"; $lowrange++ if ($lowrange % 2 == 0); open RESULTS, ">$resultFile" || die "Cannot open $resultFile for writing\n"; my $counter = 0; if ($lowrange <= 3) { if ($lowrange <= 2) { print RESULTS "2\n"; $counter++; } print RESULTS "3\n"; $lowrange = 5; $counter++; } CANDIDATE: for (my $candidate = $lowrange; $candidate <= $hirange; $candidate += +2) { for my $divisor (3 .. int(sqrt($candidate))) { next CANDIDATE unless $candidate % $divisor; } $counter++; print RESULTS "$candidate\n"; } close RESULTS; print "\nTotal amount of primes: $counter \n"; print "Your results have been saved to $resultFile\n"; __END__

------
We are the carpenters and bricklayers of the Information Age.

Vote paco for President!