Nico Rittner <> wrote:
> 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.
ie. in the first set of prints, $val is a string.
> 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 ??
When a number is "stringified", it follows the locale.
There is no need to convert number->string for the 1st "print $val;"
so the dot remains.
The 2nd "print $val;" needs to do the conversion, so it uses comma.
> Is it really true that print() will NOT
> use locale definitions?
It *is* using locale definitions.
Whenever it needs to convert a number into a string, it is using a comma,
just like it is supposed to.
><snippet>
> use strict;
> use POSIX qw(locale_h);
> use locale; # also tried without this line.
> setlocale(LC_NUMERIC,"de_DE@EURO");
^^^^^
^^^^^
Isn't strict complaining about that undeclared variable?
Is this your actual code?
> my $val;
>
> $val = "6.02";
> printf ("%.2f\n",$val);
> print $val;
It started life as a string, no need to convert a number to a string here.
> $val = 6.02;
> printf ("%.2f\n",$val);
> print $val;
It started life as a number, need to stringify it for output.
> Output:
> 6,02
> 6.02
> 13,02
>
> 6,02
> 6,02
> 13,02
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas