in reply to Coding for multiple Languages

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.

Replies are listed 'Best First'.
Re^2: Coding for multiple Languages
by Errto (Vicar) on Jan 03, 2008 at 14:57 UTC
    (and STDIN and STDOUT?)
    It doesn't. For that you need use open qw/:utf8 :std/;
Re^2: Coding for multiple Languages
by cosmicperl (Chaplain) on Jan 03, 2008 at 15:04 UTC
    The separate file is a perl file such as:-
    $stringhello = 'Hello'; $stringlogin = 'Login';...
    that's brought in with require lang.pl; I was referring to adding use utf8; to the top of that file. Wouldn't that do the same?

      Yes. It can even be in other encodings using use encoding '...';.

      You still need to handle the output, though. The strings of characters need to encoded into strings of bytes using one of the methods I posted.