Created
June 12, 2026 16:41
-
-
Save uplime/bf206b8670438a9bdbffdfc7a1d62b78 to your computer and use it in GitHub Desktop.
Comma-ize any number bigger than 999.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment