Here's my code -
BEGIN { $ENV{LC_ALL} = $ENV{LANG} = 'sv_SE.UTF-8' } use strict; use warnings; use utf8; use open ':std', ':locale'; use LWP::UserAgent qw( get ); use HTML::Strip qw( ); use HTML::Entities qw( decode_entities ); use Text::Sentence qw( split_sentences ); my $userAgent = LWP::UserAgent->new(); #$userAgent->agent('Mozilla/5.0'); my $url = "http://www.expressen.se"; my $response = $userAgent->get($url); die "Can't get $url: ", $response->status_line unless $response->is_success; my $hs = HTML::Strip->new( decode_entities => 0 ); my $parsedContent = $hs->parse( $response->content ); utf8::decode( my $decodedParsedContent = $parsedContent ); $decodedParsedContent =~ s/(\s)+/ /g; # remove double whitespace decode_entities(my $decodedParsedContentWithDecodeEntities = $decodedP +arsedContent); my @sentences = split_sentences( $decodedParsedContentWithDecodeEntiti +es ); foreach my $sentence (@sentences) { #$sentence =~ s/^\s+//; # remove leading whitespace #$sentence =~ s/\s+$//; # remove trailing decode_entities(my $sentenceDecodeEntities = $sentence); while ($sentenceDecodeEntities =~ /(\w+)/g) { print "$1 : ".$sentenceDecodeEntities."\n"; } }
One of my output lines is -
gor : BLOGG Europe Turnéblogg Mic i vĺr replokal "The Dungeon" BLOGG L +otta Gröning Krönikör Demokratifiasko...
Which looks good, however if I comment out either of the two calls to decode_entities(), I end up getting -
gor : BLOGG Europe Turnéblogg Mic i vĺr replokal "The Dungeon&quo +t; BLOGG Lotta Gröning Krönikör Demokratifiasko...
Why do I need the two calls to decode_entities()???
Thanks very much for your help!

In reply to Wierd behaviour with HTML::Entities::decode_entities() by Anonymous Monk

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.