Hi dear monks,
I came over a strage behaviour with print/say built-ins using setlocale. I tried to localize floating point representation using setlocale. I observed different behavior of print/say statements according to how I use them. If I use a point operator to concatenate some numbers and strings to a single statement
say "bla bla" . 1/2 . " bla bla prints "bla bla
0.5 bla bla". If I pass a list the localized german represantation with comma is used
say 'bla bla ', 1/2, ' bla bla' prints "bla bla
0,5 bla bla".
Please explain this behaviour if it is intended.
The code which demonstrates the problem using say and print statements is below. I use Strawberry Perl 5.10 on Windows XP SP3.
use strict;
use warnings;
use diagnostics;
use v5.10;
use locale;
use POSIX qw(locale_h);
setlocale (LC_ALL, "german") or die "failed to load locale!";
my $number = 1/2;
say 'output of say';
say $number;
say 1/2;
say 1/2 . " concatenate";
say 1/2 , " list";
say "1/2 concatenate";
say "1/2 list";
say $number . " concatenate";
say $number , " list";
say 'output of print';
print "$number\n";
print 1/2 . "\n";
print 1/2 . " concatenate\n";
print 1/2 , " list\n";
print "1/2 concatenate\n";
print "1/2 list\n";
print $number . " concatenate\n";
print $number , " list\n";
this prints on my machine:
output of say
0,5
0,5
0.5 concatenate
0,5 list
1/2 concatenate
1/2 list
0,5 concatenate
0,5 list
output of print
0,5
0.5
0.5 concatenate
0,5 list
1/2 concatenate
1/2 list
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.