Okay, a little update. Just what is going on in Perl’s mind here?

$ perl -E 'use POSIX qw(setlocale LC_NUMERIC); say 3.14; setlocale(LC_ +NUMERIC, ""); say 3.14; setlocale(LC_NUMERIC, "C"); say 3.14; setloca +le(LC_NUMERIC, ""); say 3.14; say 3.14 . "";' 3.14 3,14 3.14 3,14 3.14

Switching back and forth seems to work. When the environment locale is loaded, we get a comma, when the C locale is loaded, we get a period. Excellent.

Except for the last two. If you concat anything (could have done it with print 3.14; print "\n"; print 3.14 . "\n"; instead, for the same effect) to the float (turning it into a string much like how you turn it into a string with the print or the say directive, it won’t follow the locale rules. I’d been battling the exact opposite until now!


And when we also use Gtk which will call setlocale on the C level:

~$ perl -E 'use Gtk2 -init; use POSIX qw(setlocale LC_NUMERIC); say 3. +14; setlocale(LC_NUMERIC, ""); say 3.14; setlocale(LC_NUMERIC, "C"); +say 3.14; setlocale(LC_NUMERIC, ""); say 3.14; say 3.14 . ""; ' 3,14 3,14 3.14 3,14 3,14

The first turns into a comma, that’s good, Gtk2 set the locale to Hungarian. The second remains a comma, as expected. The third becomes a period, because of C locale. Fourth is a comma, rightfully, because of the environment locale. And the last one behaves as it should now, remaining a comma, appropriate for the environment locale being used.


In reply to Re: Perl, Gtk2 and locale — a bit of a mess by Ralesk
in thread Perl, Gtk2 and locale — a bit of a mess by Ralesk

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.