There are two key questions that need to be answered.

In this case, that means

Taking some guesses, we end up with:

use Encode qw( decode encode ); use LWP::Simple qw( get ); my $URL = ...; my $web_enc = 'UTF-8'; my $out_enc = 'iso-latin-1'; my $web_octets = get($URL); my $chars = decode($web_enc, $web_octets); my $out_octets = encode($out_enc, $chars); print($out_octets);

Note: from_to could be used as a shortcut for decode plus encode.

Ok, I kinda lied. In this case, it's not necessary to know the encoding of the downloaded content because the web server should tell us what it is.

use LWP::UserAgent qw( ); my $URL = ...; my $out_enc = 'iso-latin-1'; # Saves us from encoding chars sent to STDOUT. binmode(STDOUT, ":encoding($out_enc)"); my $ua = LWP::UserAgent->new(); my $response = $ua->get($URL); my $chars = $response->decoded_content(default_charset => 'UTF-8'); print($chars);

Update: Non-core module Term::Encoding can help determine the value for $out_enc..


In reply to Re: LWP::Simple // Special Character problems. by ikegami
in thread LWP::Simple // Special Character problems. by RipHard

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.