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 ×äš $

Enjoy, Have FUN! H.Merijn

In reply to Re: Decode character encodings, warn on user mistake by Tux
in thread Decode character encodings, warn on user mistake by ambrus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.