2

When I set my locale to it_IT.UTF-8 (export LC_ALL=it_IT.UTF-8) and run this script

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

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

I get this output:

martedì marzo 15 08:50:07 2011

but reading this (from 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 .

why does my locale-setting have an influence on the strftime-output without the use of the locale pragma?

sid_com
  • 24,137
  • 26
  • 96
  • 187
  • It seems that `POSIX` and locales is just a dark corner of Perl. See also http://stackoverflow.com/questions/3214418/is-locale-setting-global-in-perl – Eugene Yarmash Mar 15 '11 at 09:22

1 Answers1

5

POSIX::strftime is a thin wrapper around the real strftime C function call in time.h which uses the current locale. Perl doesn't go through the effort to make it conform.

DateTime has a strftime equivalent implemented in Perl that will conform to Perl's locale pragma.

Schwern
  • 153,029
  • 25
  • 195
  • 336