I created a nested hash with some sample data, and wrote it out to see how Config::General would deal with it. Then I'll use that as an exemplar to change the configuration.
I wrote:
my $conf = new Config::General(
-ConfigHash => \%Data,
-UTF8 => 1);
$conf->save_file ("output.conf");
Now I know my script is saved as UTF-8, because I can look in hex and see the bytes
E2 80 B2 in the file where one character is. But my resulting output file contains
C3 A2 C2 80 C2 B2 instead!
It encoded the individual characters E2, 80, and B2 as UTF8. But, I thought Perl 5.10 treated the source code as UTF8 naturally? Reading the docs, use encoding 'utf8' just changes the way concatenated mixed strings are upgraded or downgraded, for compatibility with length checking methods.
But adding that pragma indeed fixes the problem, and U+2032 doesn't fit in an 8-bit character, so either Config::General is doing something funny when manipulating the strings to lose the clumping, or the Perl string literal is not in UTF-8 by default?
Can someone shed light on this?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.