0
my $star = 'इस परीक्षण के लिए है';

I want to print this string as it is using encoding.

Borodin
  • 126,100
  • 9
  • 70
  • 144
  • Which terminal are you using? If the terminal handles UTF8, you should be able to print the variable to STDOUT. See [How can I output UTF-8 from Perl?](http://stackoverflow.com/questions/627661/how-can-i-output-utf-8-from-perl) – Håkon Hægland Apr 03 '16 at 12:33
  • i am using linux terminal and windows terminal – Mintu Raj Apr 03 '16 at 12:34

1 Answers1

4

You need the statement

use utf8;

at the top of your program to tell perl that the script is encoded in UTF-8. You can also write

use open qw/ :std :encoding(UTF-8) /;

to make UTF-8 the default output encoding

Your terminal must be expecting UTF-8 output. On Linux you should check the LC_TYPE environment variable

echo $LC_CTYPE

This should normally be UTF-8 but you can change it if not

On Windows this is done with code pages. For UTF-8 you need code page 65001. Use the chcp command to check and alter it

Now, provided your terminal is using a font that covers the characters you want to display, you should be able to just print $star to have the text appear on your terminal

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
Borodin
  • 126,100
  • 9
  • 70
  • 144
  • 1
    +1 It should be noted that, if using `cmd.exe` on Windows, you are going to run into [problems](https://www.nu42.com/2014/05/utf-8-ouput-from-perl-and-c-programs-in.html). Setting `STDOUT` to use the [`:unix` layer](https://www.nu42.com/2014/05/utf-8-output-from-perl-in-cmdexe-layers.html) seems to help. Using a console container such as [ConEmu](https://conemu.github.io/) will mask the problems, and file output will work fine. Also, with `cmd.exe` console set to code page 65001, keyboard input will not work properly. etc etc. – Sinan Ünür Apr 03 '16 at 18:04