Latest News
2nd January 2006
Perl offers many ways to commafy a number. That is, insert commas every three number for integers larger than 999. Here is my commafy routine:
sub commafy {
my $num = shift;
my $new = "";
while ($num =~ s/(?<=d)(d{3})$//g) {
$new = ",$1$new";
}
$new = "$num$new";
return $new;
}
It works backwards from right to the left. It uses the "new" look behind assertion in the regex. Works fine in Perl 5.8, and I think Perl 5.6.
Current Status
New a pseudocertainty episode? Yes. http://bit.ly/93m5YR
Posted: Thu Jan 28 00:49:06 +0000 2010
--Via identi.ca
About this blog
The taskboy blog is a exploration of computer technology by Joe Johnston. Topics of posts include practical examples Perl, PHP, Python and Java as well as book reviews, industry insights and miscellaneous good stuff.

