Skip to content

Instantly share code, notes, and snippets.

@uplime
Created June 12, 2026 16:41
Show Gist options
  • Select an option

  • Save uplime/bf206b8670438a9bdbffdfc7a1d62b78 to your computer and use it in GitHub Desktop.

Select an option

Save uplime/bf206b8670438a9bdbffdfc7a1d62b78 to your computer and use it in GitHub Desktop.
Comma-ize any number bigger than 999.
#!/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