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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |