Encode::Guess load ISO-8859-1

Encode::Guess load ISO-8859-1

am 27.03.2006 17:09:12 von pere.noel

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.
iso-8859-1
iso-8859-1


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 :
-----------------------------------------------------------
#!/usr/bin/perl

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 = ;
close F or die "cannot close $file: $!";
}
Encode::Guess->add_suspects('latin1');
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

am 08.04.2006 18:14:04 von rueycheng

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);