develooper Front page | perl.perl5.porters | Postings from May 2012

Question about 'perlre' Wrt locale

Thread Next
From:
Linda W
Date:
May 16, 2012 14:45
Subject:
Question about 'perlre' Wrt locale
Message ID:
4FB4200E.6030708@tlinx.org
A change that popped up in 'bash', was it started using something
similar to DOS/Windows rules for character sorting (apparently the en_US
locale doesn't know the difference between upper and lower case for sorting,
and 'a'<'A'<'b'<'B'...

To protect against this, I add "export LC_COLLATE=C" to my bash profile.

When I was reading the perlre section about the modifiers /a /d /l and /u.

I wondered when I might be at risk for a locale specific interpretation of
ranges --- so I set my LC_COLLATE var back to it's distro-default
for my locale "en_US.UTF-8".

In bash, this gives the "fun" result:

in="aAbBcCxXyYzZ"
out=${in//[a-z]}
echo out=$out
Z   #(upper case Z)

When I tried a locale specific replacement (used both, 'use locale and 
"/l" as well as each, alone) in perl of the same sort:

perl -wE 'use locale;
my $in="aAbBcCxXyYzZ";
my $out=($out=$in,($out=~ s/[a-z]//lg),$out);
print "out=$out\n";'
out=ABCXYZ;

I get the traditional, "expected" result, not the new & modern 
interpretation
that Bash is showing.

So my question is.. (be aware, I don't really like the new behavior, 
BUT... if
it IS supposed to be the locale specific behavior...)... how would one 
get a
similar butchery^h^h^h^h^h^h^h^hPOSIXly correct result?

I.e. should Perl's "use locale" have done the same?  If not, why not (other
than it's icky!)    I mean, if perl's going through the pain to put in
4 modifiers to change how substitutions and such are done, (affecting most
specifically, 'ranges', in this case), should one of them be creating 
similar
output?

linda


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About