in reply to Decode character encodings, warn on user mistake
And if you do not know the original encoding at all, but you can tell a few characters for sure, this might help:
use strict; use warnings; use Encode "decode"; binmode STDOUT, ":utf8"; my @enc = grep { !m/^mime/i } Encode->encodings (":all"); my $c = pack "H*", shift; foreach my $e (@enc) { my $x = eval { decode ($e, $c) }; !defined $x || $x =~ m/^(?:$|\x{fffd})/ and next; printf " %-30s %s\n", $e, $x; }
If you know that in your text, \xD7 is × and \xE4 is ä, then:
$ find_enc d7e4 | grep ×ä cp1250 ×ä cp1252 ×ä cp1254 ×ä cp1257 ×ä cp1258 ×ä iso-8859-1 ×ä iso-8859-13 ×ä iso-8859-15 ×ä iso-8859-2 ×ä iso-8859-3 ×ä iso-8859-4 ×ä iso-8859-9 ×ä UTF-7 ×ä $
The more you know, the smaller your result set might be. If you also know that \xF0 is đ or š, you're down to 4 or even 2:
$ find_enc d7e4f0 | grep ×äđ cp1250 ×äđ cp1258 ×äđ iso-8859-2 ×äđ iso-8859-4 ×äđ $ find_enc d7e4f0 | grep ×äš cp1257 ×äš iso-8859-13 ×äš $
|
|---|