Possibly one of these methods will help? (From perldoc perlfaq5) {see update below}:
How can I output my numbers with commas added? This subroutine will add commas to your number: sub commify { local $_ = shift; 1 while s/^([-+]?\d+)(\d{3})/$1,$2/; return $_; } This regex from Benjamin Goldberg will add commas to numbers: s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g; It is easier to see with comments: s/( ^[-+]? # beginning of number. \d{1,3}? # first digits before first comma (?= # followed by, (but not included in the match +) : (?>(?:\d{3})+) # some positive multiple of three digits. (?!\d) # an *exact* multiple, not x * 3 + 1 or whate +ver. ) | # or: \G\d{3} # after the last group, get three digits (?=\d) # but they have to have more digits after the +m. )/$1,/xg;

Update: In 352970, tachyon points out that the commify subroutine in the FAQ is pretty inefficient -- "it backtracks to do the job and also chokes on things like $1000 or 'string 123456'." I didn't know this prior to tachyon's post, so I'd suggest using the subroutine from the Perl cookbook (shown in 352970 as well as below in injunjoel's post. Learn something new every day...


In reply to Re: Formatting Data by Nkuvu
in thread Formatting Data by b310

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.