in reply to First code - Factors

You could collapse most of that into print "$_\n" for grep { 0 == $no % $_ } @int;, if you wanted to. But I have my doubts whether this is reliable for large numbers, because you'll be comparing zero to a tiny floating-point number, which is usually a bad idea.

Whether or not this is a toy program, you should also look at Math::Big::Factors: eg, factors_wheel($no, 1). Here's a hint in using the output of that function: increment hash values for each repeated factor returned, and you'll get a complete list of factors and their multiplicities.

Replies are listed 'Best First'.
Re^2: First code - Factors
by JavaFan (Canon) on Sep 22, 2010 at 11:40 UTC
    You could collapse most of that into print "$_\n" for grep { 0 == $no % $_ } @int;, if you wanted to. But I have my doubts whether this is reliable for large numbers, because you'll be comparing zero to a tiny floating-point number, which is usually a bad idea.
    What tiny floating-point numbers? '%' will always yield an integer, and since @int doesn't contain numbers exceeding $no, even $no/$_ for @int does not involve floats smaller than 1.
      Oh, you're right. I was thinking of the technique of naively dividing a number by a factor, without my paying attention to the code. Thanks!