I decided to take up your challenge. Create a single regular expression to 'commify' a number. Here is my entry:
$number =~ s/(\d+?)(?=(?:\d{3})+(?:\.|\z))/$1,/g;
Can anybody spot a case where this would not work?
Since the regular expression is looping in C code, rather than Perl code, I expect this solution to execute faster.
In reply to Re: "Commifying" a number
by MarkM
in thread "Commifying" a number
by Tanalis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |