in reply to Re: issue with Encode::Guess
in thread issue with Encode::Guess

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

Replies are listed 'Best First'.
Re^3: issue with Encode::Guess
by Corion (Patriarch) on Apr 05, 2020 at 11:01 UTC

    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.