in reply to how do I check encoding before opening FILEHANDLE

You could peek at the source of the module to see how they do it.

Also: you can change the encoding of an open filehandle using the three-arg form of binmode.

So if you know how the algorithm to figure out the encoding, you can open in byte mode, check the data, and binmode with the appropriate encoding layer.

Replies are listed 'Best First'.
Re^2: how do I check encoding before opening FILEHANDLE
by PodMaster (Abbot) on Feb 17, 2005 at 21:37 UTC
    So if you know how the algorithm to figure out the encoding, you can open in byte mode, check the data, and binmode with the appropriate encoding layer.
    Encode::Guess can be used to guess the actual encoding, but it shouldn't be neccessary (if you're lucky), as the xml file should specify the encoding, as in <?xml version="1.0" encoding="ISO-8859-1"?>

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Well, it's easy but not utterly trivial, because if you open the file in the wrong encoding and compare stings or try a regexp, the comparison will fail. (And if you claim utf8 and it isn't, you have to catch an exception that will be raised).