in reply to How to handle encodings?
- How do you handle this?
I keep everything in UTF-8, since it's something that's universal and that's understood by nearly every program
- Is it a good idea to convert incoming data to Perls internal format when processing it, and do vice versa when printing/storing processed data?
Yes, it's the way to go IMHO. You can use IO layers and Encode to do it for you.
- Does the format of the file containing the Perl code itself matter?
If there are string constants in that file, and you concatenate them to the data, it does matter. So you should decode these string constants (or keep the perl files in UTF-8, and use utf8; which does the decoding for you).
I've looked att the Encoding::Guess module, is this an option to decide the format of the incoming data?
No. Guessing encoding is not reliable, and you should avoid it by all means. Make sure that all your interfaces have a way to specify the encoding.
My concluding question: What is the best way to deal with different character sets in a system?
Keep all data internally in a consistent format, and recode at the boundary between what you consider "internal" and "external". The internal encoding should be a Unicode encoding (like UTF-8, UTF-16{l,b}e) so that you won't have any information loss during recoding. Unicode aims for round-trip conversions between non-Unicode charsets and Unicode, and for all common encodings it pretty much succeeds.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to handle encodings?
by bibliophile (Prior) on Mar 06, 2009 at 21:10 UTC | |
by moritz (Cardinal) on Mar 07, 2009 at 11:21 UTC | |
|
Re^2: How to handle encodings?
by graff (Chancellor) on Mar 07, 2009 at 17:26 UTC | |
by clinton (Priest) on Mar 07, 2009 at 19:06 UTC | |
by Narveson (Chaplain) on Mar 07, 2009 at 22:28 UTC |