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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |