#! /usr/bin/perl use Time::HiRes qw(time); use Math::Round 'nlowmult'; use Term::StatusBar; print "Enter the lower bound:\n"; chomp ($low=<>); while ($low < 1) { print "That number is not valid.\n"; print "Enter the lower bound:\n"; chomp ($low = <>); } print "Enter the upper bound:\n"; chomp ($high = <>); while ($high <= $low) { print "That number is not valid.\n"; print "Enter the upper bound:\n"; chomp ($high = <>); } $totalnumber = $high - $low; my $status = new Term::StatusBar ( label => 'Progress: ', totalItems => $totalnumber, startRow => 3, ); system (clear); print "Finding the primes between $low and $high...\n"; $status->start; $total = 0; $timestart = time; open (my $fh, ">>", primes); print $fh "#:Time(s):Result\n"; print $fh "============================\n"; close $fh; for ($i=$low; $i<=$high; $i++) { $is_prime = 1; for ($j=2; $j<=sqrt($i); $j++) { if ($i%$j == 0) { $is_prime = 0; $status->setItems($i); for (1..$_[0]){ sleep 1; $status->update; } break; } } if ($is_prime == 1) { $total++; open (my $fh, ">>", primes); $duration = time - $timestart; print $fh "$total:$duration:$i\n"; close $fh; $duration = nlowmult(0.01, time - $timestart); # print "\rFound $total primes so far in $duration seconds..."; } } print "\n";