Home: Perl Programming Help: Beginner:
Command Line Encoding Setting

New User

Dec 8, 2012, 11:58 PM

Views: 2461
Command Line Encoding Setting


I have just started to learn Perl and I have an issue with the encoding of the command prompt.

My system: Windows XP Professional SP3,
Perl version: Strawberry Perl v5.14.2 built for MSWin32-x86-multi-thread

I need to print in the command prompt some Cyrillic messages using print .

For example

print "Аз съм българин.\n";

If I save that as bg.pl and write in the command prompt

perl bg.pl

I get some ugly characters.

When I write in the console


I get

Active code page: 866

I use EditPlus editor that can save text files as ANSI, Unicode, Unicode big endian, UTF-8, UTF-8+BOM files.

Could you kindly help me on the matter?

New User

Dec 9, 2012, 10:50 AM

Views: 2445
Re: [degoor] Command Line Encoding Setting

OK, here is how I solved the matter:

I saved bg.pl in all possible formats in the text editor: ANSI, Unicode, Unicode big endian, UTF-8, UTF-8+BOM.

When I saved the file as 'Unicode' and I tried

type bg.pl

the Cyrillic letters appeared correctly.

Since chcp command showed that the code page used by the DOS prompt is 'cp866', I added after #!/perl line the following:

use encoding 'cp866';

That solved the problem.

Thanks for your reading!