develooper Front page | perl.perl5.porters | Postings from April 2013

Re: Does stringification NVs should follow POSIX::setlocale?

Thread Previous | Thread Next
From:
Karl Williamson
Date:
April 26, 2013 00:31
Subject:
Re: Does stringification NVs should follow POSIX::setlocale?
Message ID:
5179CABF.1070004@khwilliamson.com
On 11/08/2012 11:39 PM, Vladimir Timofeev wrote:
> On Thu, Nov 8, 2012 at 10:25 PM, Jan Dubois <jand@activestate.com> wrote:
>> On Thu, Nov 8, 2012 at 4:16 AM, Vladimir Timofeev <vovkasm@gmail.com> wrote:
>>> Since 5.16 perl follow current locale after POSIX::setlocale.
>>> Also stringification of NVs.
>>>
>>> But why?
>>> It can lead to very subtle bugs :-(
>>>
>>> Example:
>>> vovkasm$ perl -MPOSIX -E '$a=0.5;
>>> POSIX::setlocale(POSIX::LC_ALL,"ru_RU.UTF-8"); say "$a";
>>> POSIX::setlocale(POSIX::LC_ALL,"C"); say "$a"'
>>> 0,5
>>> 0,5
>>>
>>> Is this desired behaviour?
>>
>> I would agree that this is a bug. Especially since the locale is only
>> used for translating NV to PV, but not for PV to NV, so it breaks the
>> IV/NV/PV transparency:
>>
>> $ perl -MPOSIX -E 'POSIX::setlocale(POSIX::LC_ALL,"de_DE.UTF-8");
>> $a=0.2; say "$a"+1; '
>> 1
>> $ perl -MPOSIX -E 'POSIX::setlocale(POSIX::LC_ALL,"en_EN.UTF-8");
>> $a=0.2; say "$a"+1; '
>> 1.2
>
> Yes, and that is why I would like to know the original reasoning
> behind these changes.
> And if it is not vitally important, I would recommend to revert these changes.
>
>>
>> Cheers,
>> -Jan
>
>
>
> --
> Vladimir Timofeev <vovkasm@gmail.com>
>


I started looking into this, and ran into a more fundamental question. 
It says in perllocale.pod that locales are only paid attention to within 
the scope of a 'use locale'.  There is no such pragma in the examples 
above, therefore it seems to me that the use of setlocale shouldn't 
affect anything.  The code in the core that I'm familiar with doesn't 
look at locales unless under the scope of 'use locale'.

Am I missing something here?

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