diff --git a/perl/commas.pl b/perl/commas.pl new file mode 100755 index 0000000..17ab63a --- /dev/null +++ b/perl/commas.pl @@ -0,0 +1,19 @@ +#!/usr/bin/env perl + +foreach $arg (0..$#ARGV) { + my $num = int($ARGV[$arg]); + my $fmt = "", $cnt = 0; + + while($num > 0) { + $fmt = ($num % 10) . $fmt; + + if(++$cnt % 3 == 0 and $num >= 10) { + $fmt = "," . $fmt; + } + + use integer; + $num /= 10; + } + + print "$fmt\n"; +}