Just realized what was wrong.. setting the locale correctly in the first script fixes the problem. The script now looks like:
use strict;
use warnings;
use locale;
use POSIX qw(locale_h);
+
binmode( STDOUT, ":utf8" );
+
setlocale(LC_CTYPE, "german");
+
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";
The question I have now however is why I need to set the locale in one case (the script above) but not the other (the second script that reads from stdin in my first post).
According to http://perldoc.perl.org/functions/lc.html, my best guess is that the UTF-8 flag is set on the string when it is read from stdin, but not when the string is instantiated in the code itself. Is there a way to confirm this?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|