Hi Monks,

I use Tk's getOpenFile method to select file. But its returning path string is in UTF-8 encoding (without marking it as a UTF-8 string), and Perl's file manipulating functions (open, unlink, etc.) makes syscall directly without considering the current character encoding, so the syscall will fail when the current encoding isn't UTF-8 and pathname contains multilingual characters.

In order to get rid of this issue, the current character encoding of the OS needs to be detected. One solution is using POSIX::setlocale, but it is broken on Win32, for the encoding part in the locale string is the number of current codepage instead of standard encoding name.

Although it seems easy to get around this problem (just prepend "cp" to the number), I still wonder whether there're some generic(and elegant) way to detect the OS's current encoding across multiple platforms (*nix, Win32, MacOS, etc.). Or is there any general module on CPAN which can manipulating Unicode pathnames on many different OSes?

Any suggestion is welcome. Thanks a lot! :)


In reply to How to detect the OS's current encoding? by chaoslawful

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.