chaoslawful has asked for the wisdom of the Perl Monks concerning the following question:
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! :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to detect the OS's current encoding?
by fenLisesi (Priest) on Mar 01, 2007 at 14:24 UTC | |
|
Re: How to detect the OS's current encoding?
by dk (Chaplain) on Mar 01, 2007 at 10:32 UTC | |
by chaoslawful (Acolyte) on Mar 01, 2007 at 15:30 UTC | |
|
Re: How to detect the OS's current encoding?
by zentara (Cardinal) on Mar 01, 2007 at 13:23 UTC | |
by chaoslawful (Acolyte) on Mar 01, 2007 at 15:37 UTC | |
by zentara (Cardinal) on Mar 01, 2007 at 18:13 UTC |