It might also interest you to examine Math::Big::Factors.

Here's one way to use it, that produces pretty output. You can pipe or pass as an argument a number to factor.

use strict; use warnings; use feature qw(say); use Math::Big::Factors qw(factors_wheel); use List::AllUtils qw(max); for my $number (@ARGV ? @ARGV : <STDIN>) { chomp $number; # in case it came from stdin my %factors; $factors{$_}++ for factors_wheel($number, 1); my (@sup, @fac); for my $factor (sort { length($a) <=> length($b) or $a <=> $b +} keys %factors) { my $exp = $factors{$factor}; my $fmt = "%${\(length$factor)}s%${\(length$exp)}s"; push @sup, sprintf($fmt, '', $exp); push @fac, sprintf($fmt, $factor, ''); } my $pfx = "\t"; say join("\n", "$number:", $pfx . join(' ', @sup), $pfx . join(' * ', @fac), ''); }

In reply to Re: how to make perl only print whole numbers by Anonymous Monk
in thread how to make perl only print whole numbers by derpp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.