I would argue that the initial version, had it been sufficient, would be much easier understood by a novice than the regex solutions. Case in point: I got this function (the initial version) right three and a half times1 from scratch in a single motion without having memorized the sequence, merely by remembering the mechanics. Given the triviality of the function, that is not a feat by any means, but doing the same with any of the regex-based versions certainly would have been. I consider that anecdotal proof for this approach indeed being simpler than the regex based ones.

Dealing with the extra cases complicated it beyond a significant win though. The extended approach probably does not require much less explanation than regex based ones either. I still consider it easier to grasp, but at this point the difference isn't particularly large.

And while you're right about code that has been sunk into a project in progress, that is not the context for which I advertised this snippet. I am not telling anyone to go back and change all their commify functions to this rendition. But best practices evolved and the Perl documentation too is constantly being revised — as they should be. This was precisely an attempt2 at adding another tiny step forward to the current best practices.

Architects and engineers play on different levels under different constraints.

1 Lack of sleep notwithstanding.

2 Oh well.

Makeshifts last the longest.


In reply to Re^4: Commify numbers, the boring and straightforward way by Aristotle
in thread Commify numbers, the boring and straightforward way by Aristotle

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.