Dear Monks,
I'm expecting the following code to simply lowercase Ü (using Perl 5.8.8):
use strict;
use warnings;
use locale;
use POSIX qw(locale_h);
+
binmode( STDOUT, ":utf8" );
+
my $loc = setlocale(LC_CTYPE);
print "LC_CTYPE=$loc\n";
+
my $accented_char = "\x{00dc}"; #Upper case U with DIAERESIS
print "accented char=$accented_char\n";
+
my $lowercased = lc( $accented_char );
+
print "lowercased=$lowercased\n";
But it prints:
LC_CTYPE=en_US.UTF-8
accented char=Ü
lowercased=Ü
Based on perldoc for lc, I believe this should work, but it doesn't.
Interestingly, accepting the input on stdin (with character encoding set to UTF-8 in the terminal) lowercases Ü correctly:
use strict;
use warnings;
use Encode;
+
binmode( STDIN, ":utf8" );
binmode( STDOUT, ":utf8" );
+
+
while( my $char = <> ) {
chomp $char;
my $lc_char = lc( $char );
print "lowercased $char=$lc_char\n";
}
Any idea as to why the first script wouldn't work?
Many thanks.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.