Perl seems unable to properly handle the slash-x style octets that represent characters in the upper-ascii range or beyond--or perhaps, as is likely, I just don't know what I'm doing! With that in mind, someone can probably spot my error. Here's the issue.
I need to convert files which have stored Latin1-style characters in a (to me) non-standard UTF-8 format to "standard" UTF-8 characters (the actual characters instead of representations of them).
THIS:
\xc3\xa4 <span class="sy">\xc3\xa4</span>, <span class="sy">\xc3\x8 +4</span><span class="posg pos">Substantiv, Neutrum, das</span><span c +lass="vg v"> \xc3\x84 \xc9\x9b\xcb\x90 das \xc3\xa4; Genitiv: des \x +c3\xa4 (umgangssprachlich: -s), \xc3\xa4 (umgangssprachlich: -s) </sp +an>
Should be converted to THIS:
ä <span class="sy">ä</span>, <span class="sy">Ä</span><span class=" +posg pos">Substantiv, Neutrum, das</span><span class="vg v"> Ä ɛ +;ː das ä; Genitiv: des ä (umgangssprachlich: -s), ä (umgangsspra +chlich: -s) </span>
I've tried everything I can think of. I am able to correctly convert it in a browser by using the following sequence:
use Encode; use utf8; binmode STDOUT, ':utf8'; print "Content-Type:text/html; charset=utf-8\n"; print "Content-Language: utf8;\n\n"; my $ucode = qq|\xc3\xa4 <span class="sy">\xc3\xa4</span>, <span cla +ss="sy">\xc3\x84</span><span class="posg pos">Substantiv, Neutrum, da +s</span><span class="vg v"> \xc3\x84 \xc9\x9b\xcb\x90 das \xc3\xa4; +Genitiv: des \xc3\xa4 (umgangssprachlich: -s), \xc3\xa4 (umgangssprac +hlich: -s) </span>|; my $newcode = decode('utf8', $ucode); print "<p>$newcode</p>\n";
But if I read the line from a file, perform this conversion, and then push that line into an array and print it to a file, I still end up with the slash-x characters that I wanted to abolish! This causes me to think that Perl had not worked the magic at all--it all came from my browser. I hate to think that FireFox handles text encodings more powerfully than Perl is capable of!
What must I do?
Blessings,
~Polyglot~
In reply to Perl's encoding versus UTF8 octets by Polyglot
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |