Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Spanish locale and name sorting

by Jorge_de_Burgos (Beadle)
on May 02, 2009 at 11:40 UTC ( #761486=note: print w/replies, xml ) Need Help??


in reply to Re: Spanish locale and name sorting
in thread Spanish locale and name sorting

Maybe you expect wrong thing?

Why would you say that? The output of your code on your system shows that our expectations are right -- if you use some 1252 (I think that means Windows) locale instead of UTF-8.

This is the output of your program on my system.

Current locale is (C). unsorted use-locale no-locale - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 maceira mac alister mac alister 1 mac alister maceira mac loughlin 2 mac loughlin mac loughlin maceira 3 san esteban san esteban san esteban 4 sangregorio sangregorio san zoilo 5 san zoilo san zoilo sangregorio - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Couldn't switch locale from (es_AR.UTF-8) to (Spanish - Argentina). - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I am looking for a solution to a problem that arises under Spanish UTF-8 locales, where sorting order treats the space character as non existent.

Replies are listed 'Best First'.
Re^3: Spanish locale and name sorting
by Jorge_de_Burgos (Beadle) on May 02, 2009 at 12:16 UTC

    Down and dirty hacks are available of course. For everyday use I have come up with this:

    #!/usr/bin/perl use locale; my @list = ('maceira', 'mac alister', 'mac loughlin', 'san esteban', ' +sangregorio', 'san zoilo'); sub keeping_spaces { my $aa = $a; my $bb = $b; for ($aa) { tr/ /A/; } for ($bb) { tr/ /A/; } return $aa cmp $bb; } print "$_\n" for sort keeping_spaces @list;

    Which outputs what we would expect:

    mac alister mac loughlin maceira san esteban san zoilo sangregorio
Re^3: Spanish locale and name sorting
by Anonymous Monk on May 02, 2009 at 16:46 UTC
    Why would you say that?
    Because I don't get the results you expect :) But then I don't have es_AR.UTF-8. Your results column for use-locale seems to ignores setlocale (because it doesn't match mine), but your no-locale column matches mine. I suspect a bug in locale. Can you try again with "es_AR.UTF-8" instead of "Spanish - Argentina"?
      Can you try again with "es_AR.UTF-8" instead of "Spanish - Argentina"?

      Sure thing. As you will see, with this output of your program, we are back to the situation I asked about in the first post of this thread:

      Current locale is (C). unsorted use-locale no-locale - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 maceira mac alister mac alister 1 mac alister maceira mac loughlin 2 mac loughlin mac loughlin maceira 3 san esteban san esteban san esteban 4 sangregorio sangregorio san zoilo 5 san zoilo san zoilo sangregorio - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Current locale is (es_AR.UTF-8). unsorted use-locale no-locale - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 maceira mac alister mac alister 1 mac alister maceira mac loughlin 2 mac loughlin mac loughlin maceira 3 san esteban san esteban san esteban 4 sangregorio sangregorio san zoilo 5 san zoilo san zoilo sangregorio - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      I suspect a bug in locale.

      So do I, if I am entitled to (I don't know anything about locale).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://761486]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2023-01-28 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?