use utf8 affects string literals in the source (and STDIN and STDOUT?). Strings stored in a data file won't be affected by it.
Simply specify the encoding of the data file when opening the data file.
open(my $fh, '<:encoding(UTF-8)', $language_qfn) or die; while (<$fh>) { ... }
If the you have a handle and not a file name, use binmode.
binmode(STDIN, ':encoding(UTF-8)'); while (<STDIN>) { ... }
Or decode the string explicitly
use Encode qw( decode ); open(my $fh, '<', $language_qfn) or die; while (<$fh>) { $_ = decode('UTF-8', $_); ... }
Output is very similar. Set the encoding on the output handle or use encode.
open(my $fh, '>:encoding(UTF-8)', $output_fqn) or die; print $fh ($text);
binmode(STDOUT, ':encoding(UTF-8)'); print($text);
use Encode qw( encode ); open(my $fh, '>', $output_fqn) or die; print $fh (encode('UTF-8', $text));
Update: Added output info.
In reply to Re: Coding for multiple Languages
by ikegami
in thread Coding for multiple Languages
by cosmicperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |