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.


In reply to Re: Unable to lc upper case accented characters by Eliya
in thread Unable to lc upper case accented characters by jkeenan1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.