Gangabass has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Monks

I'm getting error "Wide character in subroutine entry at C:/Perl/site/lib/Encode.pm line 194." working with one site (via WWW::Mechanize). Here is piece of code in Encode.pm:

sub from_to($$$;$) { my ( $string, $from, $to, $check ) = @_; return undef unless defined $string; $check ||= 0; my $f = find_encoding($from); unless ( defined $f ) { require Carp; Carp::croak("Unknown encoding '$from'"); } my $t = find_encoding($to); unless ( defined $t ) { require Carp; Carp::croak("Unknown encoding '$to'"); } my $uni = $f->decode($string); $_[0] = $string = $t->encode( $uni, $check ); return undef if ( $check && length($uni) ); return defined( $_[0] ) ? length($string) : undef; }

So the main problem in

my $uni = $f->decode($string);

Server response is "text/html; charset=UTF-8" so i don't understand why i get this error.

Can you give me some hints? How i can fix it?

P.S. WWW::Mechanize is 1.60 and Encode is 2.39

Replies are listed 'Best First'.
Re: WWW::Mechanize and Wide character in subroutine entry error
by ikegami (Patriarch) on Jun 29, 2010 at 01:57 UTC
    WWW::Mechanize must have decoded it for you, so use encode($to, $s) instead of from_to($s, 'UTF-8', $to)

      But how i can tell WWW::Mechanize to use encode instead of from_to?

Re: WWW::Mechanize and Wide character in subroutine entry error
by Wolfgang (Novice) on Jun 29, 2010 at 10:29 UTC

    I had the same problem. There is no bug in Encode (well at least not in this case).
    The problem is rather where your script is calling from_to. Is that part of your own code?

    Did you check, whether the page is really valid utf-8? Might be a good idea to use some validator.

    Are you trying to convert utf-8 to iso-8859-1 which is not always possible?

    Wolfgang