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 | |
|
Re^2: Coding for multiple Languages
by cosmicperl (Chaplain) on Jan 03, 2008 at 15:04 UTC | |
by ikegami (Patriarch) on Jan 03, 2008 at 15:41 UTC |