perl 禁用"设置区域设置失败"警告以显示在屏幕上



我想禁用语言环境设置失败的警告以显示在命令行中。

在系统(AIX(中可用的语言环境中 C,POSIX,EN_US.8859-15,en_us.iso8859-1,en_us

设置的语言是" en_us"(导出$ lang = en_us(,上述列表中不可用。由于执行以下命令,请发出警告。如果从上方设置语言(导出$ 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")

你好

我保留在perl脚本中的同一命令,它发出了相同的警告。我也使用了$SIG(__WARN__),但是上述警告并未在这里捕捉。但是与未申报的变量等相关的其他警告正在捕获。一种解决方案是安装我知道的不可用的语言环境,但要寻求禁用此处,因为我的代码具有选择其他语言消息的逻辑。

那么,在屏幕上禁用这些警告的方法是什么?

您可以设置PERL_BADLANG环境变量,以忽略这些警告,如Perldoc Perllocale中的记录#temocorlosise usise usisale forlocale comparate

LANG="FOO" perl -X -e 'print "hellon";'
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

vs

PERL_BADLANG=0 LANG="FOO" perl -X -e 'print "hellon";'
hello

最新更新