Search code examples
perlformatlocalepragma

Is locale setting global in perl?


I'm debugging a perl script which looks like this (simplified):

#!/usr/bin/perl    
use strict;
use warnings;

use Evil::Module;

printf "%.3f\n", 0.1;

This script outputs 0,100 (note , instead of .). If I comment out the use Evil::Module statement, the output will be 0.100.

I believe that this is related to locale setting in the module. But locale is a lexical pragma (according to the manpage), and it's not used within the script. What's happening here?


Solution

  • The use locale pragma is lexical, but if the Evil::Module module uses POSIX::setlocale, then the locale change is global.

    See perldoc perllocale for more information.