in reply to Re^2: Detect the Charset of an file
in thread Detect the Charset of an file

->getresult is documented as

Returns the name of the detected charset or undef if no charset has (yet) been decided upon.

So if you "don't get anything back", this is most likely because the detector has not yet seen enough data to determine whether the input is utf8 or something else.

My advice is to look at your specific input data, and to remove the "special characters always in our data files", unless by these "special characters" you mean "text that we want to display". Once you have extracted the text in question, you can use some heuristics to find out if it looks like (valid) utf8, and then avoid double-encoding ("Mojibake").

Finding out if some random byte sequences are valid utf8 is most easily done by taking some non-utf8-strings, encoding them and then dumping the bytes. If you check then your new data against those byte sequences, you can likely determine whether your input already has been encoded or not.

Replies are listed 'Best First'.
Re^4: Detect the Charset of an file
by endymion (Acolyte) on Oct 21, 2013 at 14:14 UTC
    I try this tomorrow. Maybe it works. Very bad that it doesn't work with sending the whole file $file as argument to the module.