I have file /tmp/xxx
with next content:
00000000 D0 BA D0 B8 │ D1 80 D0 B8 │ D0 BB D0 B8 │ D0 BA к и р и л и к
When I read content of file and print it I get the error:
Wide character in print at ...
The source is:
use utf8;
open my $fh, '<:encoding(UTF-8)', '/tmp/xxx';
print scalar <$fh>
The output from print is:
кирилик
The use utf8
means Perl expects your source code to be UTF-8.
Your problem is that although you read the input correctly, you output the data to whatever standard output is set up to be. By default, that is not UTF-8.
The open
pragma can change the encoding of the standard filehandles, including standard output:
use open qw( :std :encoding(UTF-8) );
And, whatever is going to deal with your output needs to expect UTF-8 too. If you want to see it correctly in your terminal, then you need to set up that correctly (but that's nothing to do with Perl).