N
Nico Rittner
Hi,
i am really confused about how perl locale
deals with print() ( not printf).
See the tiny example below.
If the var- Declaration is quoted, print()
behaves like expected: printf with comma,
print with dot .. unquoted both with comma.
If arithmetic operations are done with it,
"print $val + 7" outputs the result with
a comma in it. "print $val" itself outputs
a dot like expected. What is the difference
of perl's interpretions of quoted (string)
and unqoted decimal values. And how the
hell do arithmetic operations on $val
influence print() 's behaviour ??
Is it really true that print() will NOT
use locale definitions?
I have to do some kind of mathematical
calculations, show some results (formatted)
on screen and put the results in a mysql-table,
which only expects dots as decimal seperators,
i believe.
Doing tr/,/./ or disabling locale
before writing to mysql really can't
be the right way to do it, i think.
Tanks a lot
and regards,
Nico
<snippet>
use strict;
use POSIX qw(locale_h);
use locale; # also tried without this line.
setlocale(LC_NUMERIC,"de_DE@EURO");
my $val;
$val = "6.02";
printf ("%.2f\n",$val);
print $val;
print "\n";
print $val + 7;
print "\n\n";
$val = 6.02;
printf ("%.2f\n",$val);
print $val;
print "\n";
print $val + 7;
print "\n";
</snippet>
Output:
6,02
6.02
13,02
6,02
6,02
13,02
i am really confused about how perl locale
deals with print() ( not printf).
See the tiny example below.
If the var- Declaration is quoted, print()
behaves like expected: printf with comma,
print with dot .. unquoted both with comma.
If arithmetic operations are done with it,
"print $val + 7" outputs the result with
a comma in it. "print $val" itself outputs
a dot like expected. What is the difference
of perl's interpretions of quoted (string)
and unqoted decimal values. And how the
hell do arithmetic operations on $val
influence print() 's behaviour ??
Is it really true that print() will NOT
use locale definitions?
I have to do some kind of mathematical
calculations, show some results (formatted)
on screen and put the results in a mysql-table,
which only expects dots as decimal seperators,
i believe.
Doing tr/,/./ or disabling locale
before writing to mysql really can't
be the right way to do it, i think.
Tanks a lot
and regards,
Nico
<snippet>
use strict;
use POSIX qw(locale_h);
use locale; # also tried without this line.
setlocale(LC_NUMERIC,"de_DE@EURO");
my $val;
$val = "6.02";
printf ("%.2f\n",$val);
print $val;
print "\n";
print $val + 7;
print "\n\n";
$val = 6.02;
printf ("%.2f\n",$val);
print $val;
print "\n";
print $val + 7;
print "\n";
</snippet>
Output:
6,02
6.02
13,02
6,02
6,02
13,02