Another way of testing for primes is to use the prime regex. (For small numbers at least, it can exceed the recursion limit pretty quickly for larger numbers.)
use strict; use warnings; sub prime{ (1 x shift) !~ /^1?$|^(11+?)\1+$/; } for (1..1000){ print "$_\n" if prime $_; }
In reply to Re: Primes. Again.
by thundergnat
in thread Primes. Again.
by Andrew_Levenson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |