Dirk Bremer wrote:

> I am looking for a regex to be used for comma substitution for numbers, i.e. the 
>regex would transform:
> 
> 999         = 999
> 9999       = 9,999
> 99999     = 99,999
> 999999   = 999,999
> 9999999 = 9,999,999, etc.
> 
> I tried s/(\d{3})/,$1/g, but for certain numbers it leaves a leading comma, i.e. 
>999999 = ,999,999. Please advise.


sub commify ($) {
        local $_ = shift;

return $_ if tr/0-9/0-9/ < 4;

1 while s/^\s*(-?\d+)(\d{3})/$1,$2/;
return $_;

}

-- 
   ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
  (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to