in reply to Re^2: Divisors for a number
in thread Divisors for a number

The snippet you provided prints factorisation (i.e. only prime divisors, not all divisors). Translating it to Perl is straightforward:
#!/usr/bin/perl use warnings; use strict; my $n = <>; # read the input my $r = ''; my $p = 2; while ($n > 1) { if ($n % $p == 0) { $r .= "$p, "; # . is the concatenation operator $n /= $p; } else { ++$p; } } print "$r\n";
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^4: Divisors for a number
by rasy (Initiate) on Mar 03, 2015 at 23:59 UTC
    Thank you