1 perl
我想禁用区域设置失败警告以显示在命令行上。
在系统(aix)中,可用的语言环境有 C、POSIX、en_US.8859-15、en_US.ISO8859-1、en_US
设置的语言为“EN_US”(export $LANG=EN_US),该语言在上面的列表中不可用。由于执行以下命令会引发警告。如果从上面的列表中设置语言(export $LANG=en_US),则工作正常。
# perl -X -e "print 'hello'"
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LC_ALL = (unset),
LC__FASTMSG = "true",
LANG = "EN_US"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C")
Run Code Online (Sandbox Code Playgroud)
我在 perl 脚本中保留了相同的命令,并且它抛出了相同的警告。我也用过$SIG(__WARN__),但是上面的警告在这里没有被捕获。但是与未声明的变量等相关的其他警告正在被捕获。一种解决方案是安装我知道的不可用的区域设置,但希望禁用它,因为我的代码具有选择其他语言消息的逻辑。
那么如何禁用屏幕上的这些警告呢?
您可以设置环境变量来忽略这些警告,如perldoc perllocale #Temporarily Fixing Locale ProblemsPERL_BADLANG中所述
LANG="FOO" perl -X -e 'print "hello\n";'
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "FOO"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
hello
Run Code Online (Sandbox Code Playgroud)
与
PERL_BADLANG=0 LANG="FOO" perl -X -e 'print "hello\n";'
hello
Run Code Online (Sandbox Code Playgroud)