Encode::Guess load ISO-8859-1

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
new to Perl, i'd like making use of Encode::Guess, however i get an
error message :

Can't locate object method "name" via package "iso-8859-1 or utf8"
(perhaps you forgot to load "iso-8859-1 or utf8"?) at
/Users/yvon/work/Perl/encoding-check/check_files.pl line 26.

line 26 being :
  return $decoder->name;

i don't understand this error message because perl is able to print out
two times $decoder->name giving "iso-8859-1"

i suppose i have to load another module, but which one ?

the whole script being :

use Encode::Guess;
use base qw(Encode::Encoding);

sub guessEncoding
        my ($fn) = @_;
        my $string;
                local $/;
                open F, $fn or die "can't open $file: $!";
                $string = <F>;
                close F or die "cannot close $file: $!";
        my $decoder = Encode::Guess->guess($string);
        return $decoder->name;

print guessEncoding("apple-mac-roman--ISO-8859-1.html");
print "\n";
print guessEncoding("comparaison-encodages--ISO-8859-1.html");
print "\n";
print guessEncoding("cp1252--UTF-8.htm");
print "\n";
print guessEncoding("Frap--CP-1252.html");
print "\n";

une bévue

Re: Encode::Guess load ISO-8859-1

I didn't try your code, but it seems Encode::Guess will croak when it
encounters two or more suspects.  According to Encode::Guess manpage,
you can add the following code to figure out what's going on.

my $decoder = Encode::Guess->guess($data);
die $decoder unless ref($decoder);
my $utf8 = $decoder->decode($data);

Site Timeline