length returns the length (number of characters) in a string. Because you were setting the string to empty I used length to test for that condition and skip the empty string.
Others have provided better solutions. I was more interested in keeping to the essential structure of your code and using that as a springboard for teaching a little Perl. I seem to have achieved that. :)
In reply to Re^5: Primes. Again.
by GrandFather
in thread Primes. Again.
by Andrew_Levenson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |