develooper Front page | perl.perl5.porters | Postings from September 2018

[perl #133504] Issues with thousands separators in perllocale

Thread Previous | Thread Next
James E Keenan via RT
September 8, 2018 15:22
[perl #133504] Issues with thousands separators in perllocale
Message ID:
On Sat, 08 Sep 2018 11:00:00 GMT, wrote:
> Adding thousands separators to a number is a rather common operation.
> Most languages use a printf format string like "%'d", but Perl does
> not support it. I suggest that you add this feature and be done with
> it.
> Otherwise, searching the Internet will throw up a few alternatives
> with different degrees of trouble. The following official Perl
> documentation page has example code for that task:
> Search for "Format command line params for current locale" in that
> page to find the example code I am talking about.
> My first impression when looking at that example was: A "1 while" loop
> with a cryptic regex inside... what an alarming Perl nerdiness sign...
> A traditional loop without regular expressions is easier to
> understand. Search for "This is for manually testing of
> AddThousandsSeparators()" in the following Perl script I recently
> wrote for an alternative implementation.
> I have done a quick benchmark, and my loop version is much faster, at
> least with Perl v5.22.1.
> One bad practice that stands out in the perllocale example is the
> usage of 2 variables with the same name but with different types,
> namely $grouping and @grouping. Furthermore, I would not encourage
> implicit usage of special variable $_ anymore. Using named variables
> makes the code easier to grasp.
> But more seriously, the perllocale example code does not work
> correctly with the Spanish locale, where the thousands separator is
> the period ('.') character, probably because that character has a
> special meaning in regular expressions. I guess some quoting is
> necessary.

OP and list:  Please review patch attached.

Thank you very much.
James E Keenan (

via perlbug:  queue: perl5 status: open

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About