There are a range of variations on the commify theme. That faq version is probably the worst. It is inefficient as it backtracks to do the job and also chokes on things like $1000 or 'string 123456'. The regex in my sub is one of merlyns creations but it chokes on >3 numbers after the decimal point without handling them separately. The Perl cookbook version:
sub commify { my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; return scalar reverse $text; }
Is more more fault tolerant than the one from the faq.
cheers
tachyon
In reply to Re: Re: Re: Numbers with commas
by tachyon
in thread Numbers with commas
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |