Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^4: Spoiled by Perl (sorting sugar)

by LanX (Sage)
on Oct 31, 2021 at 22:38 UTC ( #11138284=note: print w/replies, xml ) Need Help??


in reply to Re^3: Spoiled by Perl (sorting sugar)
in thread Spoiled by Perl

thanks! :)

> The dispatcher does that by finding the appropriate multi-sub that implements the actual comparison.

ehm ... if I have an array with numbers and strings it will implicitly decide based on the type of $a and $b which comparison to apply?

> Rakus Str class is fully Unicode aware and by default sorts characters on the numeric value of the codepoint.

I'm not sure if that's sufficient to handle different standards.

E.g. the telephone book in Germany has another sorting than the dictionaries.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

update

clearer rewording

Replies are listed 'Best First'.
Re^5: Spoiled by Perl (sorting sugar)
by raiph (Deacon) on Dec 22, 2021 at 01:36 UTC
    > if I have an array with numbers and strings it will implicitly decide based on the type of $a and $b which comparison to apply?

    It will decide for you if you don't explicitly direct it to do otherwise. By default, given a number and a string to compare, it will coerce the number to a string. But if both elements being compared are numbers it will compare them numerically. If you want to sort all numbers as strings, you must say so, eg by passing `~*` as the comparator.

    > I'm not sure if \sorting by codepoint is\ sufficient to handle different standards. E.g. the telephone book in Germany has another sorting than the dictionaries.

    Use https://docs.raku.org/routine/collate instead of `sort`.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2023-03-30 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (74 votes). Check out past polls.

    Notices?