I have some Perl code which is executed in a context where all command line arguments, inputs and outputs are encoded in the encoding given by the LC_CTYPE
environment variable (or more generally the LC_CTYPE
setting determined from the environment). This is exactly what use locale
is for, right?
$ echo àé | perl -e 'use locale; print uc <>'
ÀÉ
This works in unibyte locales such as Latin-1, but not in UTF-8, where this program outputs àé
on my Debian wheezy machine.
perl -CLADS -e 'use locale; print uc <>'
seems to do the right thing in unibyte locales and UTF-8, at least according to my understanding of the documentation of -C
. I don't understand how I'm supposed to deduce that from the perllocale
documentation though, nor what would happen in multibyte locales other than UTF-8.
Furthermore I actually don't want to run the whole program in this mode, only one code block. In fact I can't pass parameters to the Perl interpreter, I can only pass a string to a Perl script which calls eval
on that string. use locale
's local scope would be just fine, but how do I activate -C
from within?
The read-only magic variable
${^UNICODE}
… so not that then.
How do I run a snippet of Perl code in a mode where all strings (including @ARGV
and file input/output) are interpreted according to the locale indicated by the environment?