We Spanish-speaking people would expect the sorted list to come out with all "mac something" and all "san something" before "maceira" and "sangregorio" respectively, making these longer words come out after surnames whose first word is shorter ("mac" and "san").
Maybe you expect wrong thing?
#!/usr/bin/perl --
use strict;
use warnings;
localsort("C");
localsort("Spanish - Argentina");
sub localsort
{
use POSIX qw(setlocale LC_CTYPE);
my( $wantlocale ) = @_;
my $curlocale = setlocale(LC_CTYPE);
my $setlocale = setlocale(LC_CTYPE,$wantlocale);
if( not $setlocale ){
print "Couldn't switch locale from ($curlocale) to ($wantlocal
+e).\n";
} else {
print "Current locale is ($setlocale).\n";
my @list = ('maceira', 'mac alister', 'mac loughlin',
'san esteban', 'sangregorio', 'san zoilo');
my @yes = do {
use locale;
sort @list;
};
my @no = do {
no locale;
sort @list;
};
printf " %-20s %-20s %-20s\n", qw[unsorted use-locale no-lo
+cale ];
print '- ' x 33,"\n";
for my $i( 0 .. $#list ){
printf "%3d %-20s %-20s %-20s\n", $i, $list[$i], $yes[$i],
+ $no[$i];
}
}
print '- ' x 33,"\n";
setlocale(LC_CTYPE,$curlocale);#restore
}
__END__
Current locale is (C).
unsorted use-locale no-locale
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0 maceira mac alister mac alister
1 mac alister mac loughlin mac loughlin
2 mac loughlin maceira maceira
3 san esteban san esteban san esteban
4 sangregorio san zoilo san zoilo
5 san zoilo sangregorio sangregorio
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Current locale is (Spanish_Spain.1252).
unsorted use-locale no-locale
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0 maceira mac alister mac alister
1 mac alister mac loughlin mac loughlin
2 mac loughlin maceira maceira
3 san esteban san esteban san esteban
4 sangregorio san zoilo san zoilo
5 san zoilo sangregorio sangregorio
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|