Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autodetect console output encoding in perl

I have a perl script that prints some information to console in Russian. Script will be executed on several OSes, so console encoding can be cp866, koi8-r, utf-8, or some other. Is there a portable way to detect console encoding so I can setup STDOUT accordingly so the text is printed correctly?

like image 462
n0rd Avatar asked Oct 14 '22 04:10

n0rd


2 Answers

If you're on Windows, there's Win32::Codepage.

like image 155
Snake Plissken Avatar answered Oct 20 '22 15:10

Snake Plissken


use open ':locale';

like image 37
daxim Avatar answered Oct 20 '22 16:10

daxim