user1064540
user1064540

Reputation: 31

How to get the default encoding of current OS in perl script?

How can I get the default encoding used by current platform? Is there any available module in CPAN or with the distribution of Perl itself? I can't find the solution in perl.org

Upvotes: 3

Views: 433

Answers (1)

Tanktalus
Tanktalus

Reputation: 22274

See I18N::Langinfo.

$ LANG=en_US.UTF-8 perl -MI18N::Langinfo=langinfo,CODESET -E 'say langinfo(CODESET())'
UTF-8
$ LANG=C perl -MI18N::Langinfo=langinfo,CODESET -E 'say langinfo(CODESET())'
ANSI_X3.4-1968
$ LANG=ja_JP.eucjp perl -MI18N::Langinfo=langinfo,CODESET -E 'say langinfo(CODESET())'
EUC-JP

This is probably what you're looking for. If you follow the code in I18N::Langinfo, you can see how it discovers what locale to use for returning this.

Upvotes: 1

Related Questions