#!/usr/bin/perl
use warnings;
use strict;
use POSIX qw(locale_h);

my $pi = 4 * atan2(1, 1);

print "localetest 1.1\n";
print "platform: $^O\n";
foreach my $var ( qw(LANG LC_NUMERIC LC_ALL) ){
    printf "ENV{$var} = %s\n", $ENV{$var} || '';
}
my $lconv = POSIX::localeconv();
print "decimal_point= ", $lconv->{decimal_point},"\n";

print "\n";
{
    print "before any locale messing\n";
    print "effective LC_NUMERIC: ".setlocale(LC_NUMERIC)."\n";
    print "print pi: $pi\n";
    printf "printf pi: %f\n", $pi;
}
print "\n";
{
    use locale;
    print "use locale\n";
    print "effective LC_NUMERIC: ".setlocale(LC_NUMERIC)."\n";
    print "print pi: $pi\n";
    printf "printf pi: %f\n", $pi;
}
print "\n";
{
    no locale;
    print "no locale\n";
    print "effective LC_NUMERIC: ".setlocale(LC_NUMERIC)."\n";
    print "print pi: $pi\n";
    printf "printf pi: %f\n", $pi;
}
print "\n";
{
    setlocale(LC_NUMERIC, '');
    print "LC_NUMERIC changed to (empty string)\n";
    print "effective LC_NUMERIC: ".setlocale(LC_NUMERIC)."\n";
    print "print pi: $pi\n";
    printf "printf pi: %f\n", $pi;
}
print "\n";
{
    setlocale(LC_NUMERIC, 'C');
    print "LC_NUMERIC changed to C\n";
    print "effective LC_NUMERIC: ".setlocale(LC_NUMERIC)."\n";
    print "print pi: $pi\n";
    printf "printf pi: %f\n", $pi;
}
print "\n";
{
    setlocale(LC_NUMERIC, 'nb_NO.utf8');
    print "LC_NUMERIC changed to nb_NO.utf8\n";
    print "effective LC_NUMERIC: ".setlocale(LC_NUMERIC)."\n";
    print "print pi: $pi\n";
    printf "printf pi: %f\n", $pi;
}
print "\n";
{
    setlocale (LC_NUMERIC, 'de_DE');
    print "LC_NUMERIC changed to de_DE\n";
    print "effective LC_NUMERIC: ".setlocale(LC_NUMERIC)."\n";
    print "print pi: $pi\n";
    printf "printf pi: %f\n", $pi;
}
print "\n";
{
    setlocale(LC_NUMERIC, '');
    print "LC_NUMERIC changed to (empty string) (again)\n";
    print "effective LC_NUMERIC: ".setlocale(LC_NUMERIC)."\n";
    print "print pi: $pi\n";
    printf "printf pi: %f\n", $pi;
}
print "\n";
{
    $ENV{LC_ALL} = 'C';
    setlocale(LC_NUMERIC, '');
    print "LC_NUMERIC changed to (empty string) with \$ENV{LC_ALL}=C\n";
    print "effective LC_NUMERIC: ".setlocale(LC_NUMERIC)."\n";
    print "print pi: $pi\n";
    printf "printf pi: %f\n", $pi;
}
print "\n";
