Bored Code: Primes in Perl

Yet another boring day at the office, so I decided to dust off my Perl book and try to relearn some basic chops in the language and maybe find a good use for it. ¬†Unfortunately that was not the case and in the process of getting myself familiar with it I ported some old code I wrote for artificially creating a load on my servers by crunching prime numbers. ¬†Its a pretty ghetto piece of code and I’m not sure about its limitations so if it causes your machine to catch fire or start making noises like a dying goat I’m not responsible, actual bad code after the break.


$start = 2;
$count = 0;

print "end: ";
$stop = ;

for($i = $start; $i <= $stop; $i++){

$multiples = 1;

for($ii = 2; $ii <= sqrt($i/2); $ii++){ if($multiples >= 2)
if($multiples == 1){
$diff = $i % $ii;
if($diff == 0)
if($diff > 0)
# no multiple found
if($multiples == 1)
print "$in";
print "nTotal Prime Numbers: $countn";

2 thoughts on “Bored Code: Primes in Perl”

  1. Does your website have a contact page? I’m having trouble locating it but, I’d like to send you an e-mail. I’ve got some recommendations for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it grow over time.


Leave a Comment

Close Bitnami banner