in reply to Unable to lc upper case accented characters
Get rid of the locale stuff, and tell Perl what your input and (desired) output encodings are:
#!/usr/bin/perl -w use strict; use feature qw( :5.10 ); use Carp; my $file = q{./yard}; open my $IN, '<:encoding(ISO8859-1)', $file or croak; binmode STDOUT, ":utf8"; # assuming your terminal is UTF-8 while (my $l = <$IN>) { # $l is now a Unicode/text string chomp $l; say "1: $l"; say "2: ", xlc($l); } ... sub xlc as you have it
Output:
1: CLÉ USB 2: Clé Usb 1: CLÉMMY USB 2: Clémmy Usb
Using the PerlIO layer ":encoding(ISO8859-1)" with open tells Perl that your input is in ISO8859-1, and has the effect of decoding the data into Perl's internal Unicode format, so ucfirst etc. will work correctly.
The general idea is to decode on input, and encode on output. Perl will then (ideally) do the rest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unable to lc upper case accented characters
by jkeenan1 (Deacon) on Feb 19, 2011 at 03:06 UTC |