perl-unicode

Re: Help with uc and lc and utf8

2004-11-06 07:30:07
Dan Kogai wrote:

Make sure:

* You have saved your script in UTF-8, not Latin1
* use utf8 to make sure string literals are treated as UTF-8 strings
* if you print, set filehandle layer to ":utf8".

Try the sript below (be sure to save it in UTF-8). I got "KÄThe => käthe".

#
use strict;
use utf8;
my $fname = 'KÄThe';
my $lc_fname = lc($fname);
binmode STDOUT => ":utf8";
print "$fname => $lc_fname\n";
__END__

Or, if you want to keep your script in the Latin1 encoding and also want the output printed in Latin1 instead of UTF-8, I would use

use strict;
use Encode ();
my $fname = 'KÄThe';
$fname = Encode::decode('iso-8859-1', $fname, Encode::FB_XMLCREF);
my $lc_fname = lc($fname);
binmode STDOUT => ":encoding(iso-8859-1)";
print "$fname => $lc_fname\n";
__END__


Is there any advantage in saving the script in UTF-8?

rob.

<Prev in Thread] Current Thread [Next in Thread>