2

当我将我设置localeit_IT.UTF-8(export 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 .

为什么我的语言环境设置会在不使用locale编译指示的情况下影响 strftime 输出?

4

1 回答 1

5

POSIX::strftime是对使用当前语言环境的真实strftimeC 函数调用的薄包装。time.hPerl 没有努力使其符合要求。

DateTime 在 Perl 中实现了一个等效的 strftime,它将符合 Perl 的 locale pragma。

于 2011-03-15T10:08:26.707 回答