In the code below I added much diagnostics to show the problem - but the basic situation is following. I have a UTF-8 file with some HTML entities. The HTML::LinkExtractor parser decodes HTML entities as Latin 1 characters so in the output I get a mix of UTF8 and Latin 1 and I have no idea what I could do with it.
use HTML::LinkExtractor;
use Encode qw/_utf8_on is_utf8/;
use open OUT => ':utf8';
my $utf8 = do { local $/; <DATA> };
my $LX = HTML::LinkExtractor->new(undef, undef, 1);
$LX->parse(\$utf8);
for my $l (@{$LX->links}){
if($l->{tag} eq 'a'){
my $character = substr($l->{_TEXT}, 0, 1);
print "Character: $character\n";
print "Code: ", ord($character) , "\n";
print "utf8 flag: " , is_utf8($character), "\n";
_utf8_on($character);
print "Character: $character\n";
print "Code: ", ord($character) , "\n";
print "utf8 flag: " , is_utf8($character), "\n";
}
}
__DATA__
<html>
<HEAD>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
</HEAD>
<a href="http://www.pl/">ó</a>
</html>
__OUTPUT__
Character: ó
Code: 243
utf8 flag:
Wide character in print at a.pl line 15, <DATA> line 1.
Character: ó
Malformed UTF-8 character (unexpected non-continuation byte 0x00, imme
+diately after start byte 0xf3) in ord at a.pl line 16, <DATA> line 1.
Code: 0
utf8 flag: 1
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.