Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Changing ASCII collating sequence for sort

by graff (Chancellor)
on Apr 17, 2022 at 21:22 UTC ( [id://11143038]=note: print w/replies, xml ) Need Help??


in reply to Changing ASCII collating sequence for sort

I think your problem might be that in the tr/.../.../ operator inside your sort block, you forgot to put a backslash-escape in front of the hyphen characters.

When used within the left or right side of the tr/// operator, hyphen is "magic": it interpolates to the set of characters between the preceding and following character, so ,-; (in the left-hand character sequence) becomes ,-.\/0123456789:;

(and in the right-hand sequence, ,-. "becomes" ,-. because ASCII arranges those three characters as adjacent in exactly that order, so putting the backslash escape in front of that hyphen just happens to make no difference)

Replies are listed 'Best First'.
Re^2: Changing ASCII collating sequence for sort
by ibm1620 (Hermit) on Apr 17, 2022 at 23:38 UTC
    This neatened it up a bit ...
    my @sorted_list = sort { tl($a) cmp tl($b) } @list; sub tl { return shift =~ tr / .,\-;:!?"'`_#$%&*+\/|=@\\^~()<>[]{}0123456789AaBbCcDdEeF +fGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz / -~/r; }
Re^2: Changing ASCII collating sequence for sort
by ibm1620 (Hermit) on Apr 17, 2022 at 23:20 UTC
    Precisely. Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-29 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found