Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Spoiled by Perl (sorting sugar)

by holli (Abbot)
on Oct 31, 2021 at 22:29 UTC ( [id://11138283]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    # cmp. Generic, "smart" three-way comparator.
    
    ...
    
    # Compares strings with string semantics, numbers with number semantic
    +s, Pair objects first by key and then by value etc.
    # if $a eqv $b, then $a cmp $b always returns Order::Same. Otherwise O
    +rder::Less or Order::More.
    
  2. or download this
    dd 'a ä b'.comb.sort;
    (" ", " ", "a", "b", "ä").Seq;
    
  3. or download this
    subset CzechString of String;
    multi sub infix:<cmp>(CzechString $a, CzechString $b) {
      # sort logic here
    }
    
  4. or download this
    sub czech-sort(String $a, String $b) {
      # sort logic here
    }
    
    @czech-words.sort( &czech-sort );
    
  5. or download this
    dd ([1,'z'], [2,'a'], ['1', 'a']).sort( *.[0,1] );
    (["1", "a"], [1, "z"], [2, "a"]).Seq
    
    dd ([1,'z'], [2,'a'], ['1', 'a']).sort( { $^a[0] <=> $^b[0] || $^a[1] 
    +cmp $^b[1] });
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-09-14 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (21 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.