Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Sorting (GRT) and locale issues

by chrism01 (Friar)
on Nov 15, 2007 at 05:11 UTC ( [id://650919]=note: print w/replies, xml ) Need Help??


in reply to Sorting (GRT) and locale issues

Now I'm confused. According to BrowserUK:

That way is to use pack to convert the numeric fields into binary values that will sort correctly using a string comparison function. It is convenient that binary encode integers (NOTE:In 'network' format only. That is 'N'&'n' *NOT* 'V'&'v') will sort correctly using a string comparison function.

Are you saying that although I always use locale; to ensure a prog behaves correctly in the local locale (eg sorting), there's something special about GRT that means I have to turn it off?

Incidentally, his results are sorted by num, then letter.

Chris

Replies are listed 'Best First'.
Re^2: Sorting (GRT) and locale issues
by ikegami (Patriarch) on Nov 15, 2007 at 05:38 UTC

    According to your locale, a byte with value 97 should be sorted before a byte with value 66.
    That's fine if you're sorting iso-latin-1 text. It means "a" will be sorted earlier than "B".
    That's not fine if you're sorting numbers in their native format.

    @a = map unpack('N', $_), sort map pack('N', $_), 65, 66, 67, 97, 98, 99; => 97, 65, 98, 66, 99, 67 using "use locale" on your system. a A b B c C => 65, 66, 67, 97, 98, 99 using "no locale". A B C a b c

    So yeah, you'd have to turn it off when it's comparing bytes representing numbers. But since you want it on for when it's comparing bytes representing text, you have a problem.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-26 04:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found