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

[perl #133504] Issues with thousands separators in perllocale

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
September 8, 2018 15:22
Subject:
[perl #133504] Issues with thousands separators in perllocale
Message ID:
rt-4.0.24-30213-1536420144-1594.133504-15-0@perl.org
On Sat, 08 Sep 2018 11:00:00 GMT, rdiezmail-perl@yahoo.de 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:
> 
> https://perldoc.perl.org/perllocale.html
> 
> 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.
> 
> https://github.com/rdiez/Tools/blob/master/AnnotateWithTimestamps/AnnotateWithTimestamps.pl
> 
> 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 (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=133504

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About