http://www.perlmonks.org?node_id=761449


in reply to Spanish locale and name sorting

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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -