Search code examples
windowsperlcharacter-encodinglocale

Get current system local encoding in Perl on Windows


I need to get the current encoding according to the system local settings. I'm looking for such function working this way:

my $sysEncoding = getSystemEncoding();
#and now $sysEncoding equals e.g. 'windows-1250'

I looked everywhere on the internet. I've found just the module PerlIO::locale. But I thing that the system encoding should be recognized easier without additional modules.


Solution

  • use Win32::API;
    if (Win32::API->Import('kernel32', 'int GetACP()')) {
        $enc = GetACP();
        print "Current local encoding is '$enc'\n";
    }
    

    Thanks for hint to Ikegami.