That's a lot of code for what should be fairly straightforward:
my $sep = ','; my $number = '12345678.27'; print MakeThousands($number), "\n"; sub MakeThousands { local $_ = reverse(shift()); s/(\d{3})(?=\d)(?!\d*\.)/$1$sep/go; return scalar(reverse()); }
I know in Perl there's always a balance to be struck between making code clear and keeping it concise (at least for me), but when you have three times as much code to do something fairly basic, you run the risk of adding bugs through typos, having slower execution, etc. If I just want to print numbers like "12,345,678.27", why use more code than is necessary? If you abstract out the thousands separator, this shouldn't be a sub you touch more than once. Speaking of slower code, you mentioned something about performance. Your solution is roughly twice as slow as the one I have above:
Benchmark: timing 5000000 iterations of MakeThousands, Thousandformat. +.. MakeThousands: -1 wallclock secs ( 0.06 usr + 0.00 sys = 0.06 CPU) @ + 83333333.33/s (n=5000000) Thousandformat: 1 wallclock secs ( 0.12 usr + 0.00 sys = 0.12 CPU) +@ 41666666.67/s (n=5000000)
If execution speed is really your #1 concern, you might take an eye toward simplification.

In reply to Re: Formating numbers with thousand separator - Solution for web-applications by wee
in thread Formating numbers with thousand separator - Solution for web-applications by Zzenmonk

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.