in reply to Re^3: Lost in encoding in Twig
in thread Lost in encoding in Twig
I do not think I need utf8 as my perl is v5.18 (debian jessie).
That's fine (assuming you are correct). If you are relying on new features such as this in your code, it is probably a good idea to specify that minimum version of perl at the top so that this will trap any otherwise confusing errors should you (or someone else) try to run it on an older perl. eg:
use 5.018;I can use "keep-encoded" to make it work (in this case), but I would like to understand...
In a nutshell, to get unicode (and more specifically utf8) to work properly in perl you have to decode your inputs and encode your outputs. In the script here, you have no inputs to worry about because the data is hardcoded in your source. The output however does matter because you are printing this data to a file and so have to encode it first. You can do that manually, but it's generally considered a better idea to open the file with the :utf8 layer via binmode (or directly with open) so that it all gets encoded as it passes out through the I/O system. See also PerlIO::encoding.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Lost in encoding in Twig
by pcouderc (Monk) on Jan 09, 2015 at 14:59 UTC | |
by hippo (Archbishop) on Jan 09, 2015 at 15:36 UTC |