Fetching the charset when set in meta.

Bill Moseley <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.lwp
Message-ID <[email protected]>
$response->headers->as_string shows this:

    [...]
    Content-Length: 17604
    Content-Type: text/html
    Content-Type: text/html;charset=UTF-8
    Last-Modified: Mon, 23 Oct 2006 14:32:14 GMT
    [...]

Is there a better way to grab the charset than this?

    my $charset;
    for ( $response->header('content-type') ){
        $charset = $1 if /\bcharset=([^;]+)/;
    }
    my $content = Encode::decode( $charset, $response->content )
        if $charset;


I'm assuming that the last Content-type header found is the charset to
use.

    my ($ct, $other) = $response->content_type;

is only returning the first Content-Type header.


How do other's decode content fetched with LWP?  Do you parse out
charset and then decode it like above?


Doesn't that seem like something that should be part of LWP (or some
sub-class)?

    use LWP::Simple;
    $content = get( $url );

Shouldn't $content be decoded there?


-- 
Bill Moseley
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.