2011-03-15 52 views
2

当我把我的localeit_IT.UTF-8(出口LC_ALL = it_IT.UTF-8),并运行此脚本使用的语言环境 - 问题

#!/usr/bin/env perl 
use warnings; 
use 5.012; 
use POSIX qw(strftime); 

say strftime "%A %B %e %H:%M:%S %Y", localtime; 

我得到这样的输出:

martedì marzo 15 08:50:07 2011 

但阅读本(从The-use-locale-pragma):

By default, Perl ignores the current locale. The use locale pragma tells Perl to use the current locale for some operations: ... The POSIX date formatting function (strftime()) uses LC_TIME .

为什么我的语言环境设置对strftime输出有影响,而不使用locale编译指示?

+0

看来'POSIX'和语言环境只是Perl的一个黑暗的角落。另见http://stackoverflow.com/questions/3214418/is-locale-setting-global-in-perl – 2011-03-15 09:22:59

回答

5

POSIX::strftime是一个使用当前语言环境的实际strftime C函数调用的薄包装器time.h。 Perl没有经过努力使其符合。

DateTime has a strftime equivalent在Perl中实现,将符合Perl的语言环境编译指示。