我在Linux系统(Ubuntu)上运行Perl时遇到问题:
user@Box:~$ perl -e exit
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_US:en",
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LANG = "en_DK.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_DK.UTF-8").
谷歌搜索显示,这通常与引用缺少的语言环境的环境变量有关,但是所有语言环境似乎都在那里:
user@Box:~$ locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
C
en_DK.utf8
en_GB.utf8
en_US
en_US.iso88591
en_US.utf8
POSIX
我已经尝试安装所有的en,但这似乎并没有影响任何东西。
在写这个问题时找到了答案:
罪魁祸首是LC_CTYPE=UTF-8
,它在macOS中显然是完全有效的(Perl会在那里接受它),但在Linux上则不然。为了避免它,可以如下覆盖LC_CTYPE
:
root@Box:~# update-locale LC_CTYPE=en_US.UTF-8
退出并重新登录后,Perl将不再抱怨。
user@Box:~# perl -e 'print "Hack the Planet!\n"'
Hack the Planet!