perl/commas.pl: comma-ize numbers greater than 999

This commit is contained in:
Nick Chambers 2022-01-08 02:41:03 -06:00
parent 23505bf8a5
commit 7da798d8fa
1 changed files with 19 additions and 0 deletions

19
perl/commas.pl Executable file
View File

@ -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";
}