Fellow monks,

We have run into a very strange issue with locales using comma as the decimal separator. Not sure where exactly the problem lies, but it seems that no matter if we say no locale; so we would be exempt from locale rules in a block — and this we need so numbers in JSON remain… well, numbers —, as long as we have an initialised Gtk2, we will get comma-separated floats.

~$ locale < ... all set to hu_HU.UTF-8 ... > [001] ~$ perl -e 'printf(q{%f}, 123.456);' 123.456000 [002] ~$ perl -e 'use locale; printf(q{%f}, 123.456);' 123.456000 [003] ~$ perl -e 'use locale; use POSIX; POSIX::setlocale("LC_ALL", "h +u_HU.UTF-8"); printf q{%f}, 123.456;' 123.456000 [004] ~$ perl -e 'use Gtk2 -init; printf(q{%f}, 123.456);' 123,456000

I might not know my way around locale, but I thought the line in 003 would result in a comma... In any case, the moment Gtk2 enters the game, like in 004, it turns into a comma. Then we experimented further:

[005] ~$ perl -e 'use Gtk2 -init; print unpack("H*", 123.789) . "\n";' 3132332c373839 [006] ~$ perl -e 'use locale; print unpack("H*", 123.789) . "\n";' 3132332e373839 [007] ~$ perl -e 'print unpack("H*", 123.789) . "\n";' 3132332e373839 [008] ~$ perl -e 'use Gtk2 -init; print unpack("H*", "123.789") . "\n" +;' 3132332e373839 [009] ~$ perl -e 'use Gtk2 -init; print unpack("H*", 123.789 . "") . " +\n";' 3132332c373839

Notice how even unpack already only knows about the commaed string, once Gtk2 is in play — we haven’t found a way to stringify the number (in our real-world use case: the result of a time() command — without the locale mangling it.

So... any ideas? What are we doing wrong? Is there a way around this without forcing the locale to be C (or something “proper”) before Gtk2 gets initialised, ie. without actually breaking the entire locale thing?


In reply to 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.