in reply to issue with Encode::Guess

So, how does your program behave? And how does that differ from what you expect?

Also, what encoding is your input file in? Latin-1 ? UTF-8? ISO-8859-15?

Replies are listed 'Best First'.
Re^2: issue with Encode::Guess
by toohoo (Beadle) on Apr 05, 2020 at 10:51 UTC

    Hello @Corion,

    in this first step my programm should behave in the following way:
    it should in this first step name me in what encoding the input file is.
    In a further step it should convert from input encoding to UTF-8. But this is not programmed yet.

    Because in the future my programm will be called with many input files, I don't know, what encoding the input files will be.
    If you point at my example code so asume it is encoding ANSI. The special case are the german Umlauts like entity auml.

    Thanks

      This code:

      my $encodings_test = 'ascii cp1252 cp437 cp850 iso-8859-1 utf-8-strict + utf8'; my $decoder = guess_encoding($data, qw/$encodings_test/); print "decoder: $decoder\n";

      ... does not what you think it does. qw does not interpolate strings into lists. You likely want:

      my @encodings_test = qw(ascii cp1252 cp437 cp850 iso-8859-1 utf-8-stri +ct utf8); my $decoder = guess_encoding($data, @encodings_test);

      ... or if you want to keep your list of encodings as a string (why?!), split it into a list:

      my $encodings_test = 'ascii cp1252 cp437 cp850 iso-8859-1 utf-8-strict + utf8'; my @encodings_test = split /\s+/, $encodings_test; my $decoder = guess_encoding($data, @encodings_test); print "decoder: $decoder\n";

        or if you want to keep your list of encodings as a string

        It could come from a config file.

        Hello @Corion,

        This was exactly the point that did lack. Now it works.

        Many thanks for your help.