Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

RFC: Simple switches for 'sort' and list 'reverse'

by rsFalse (Chaplain)
on Mar 05, 2021 at 16:32 UTC ( [id://11129169]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/perl
    
    ...
            $ref->[ $i ] cmp $ref->[ $i + 1 ] and do { ;;; };
        }
    }
    
  2. or download this
    my @original = ( 5, 'A' .. 'C', 0, 4 );
    my @sorted = sort sort_sub @original;
    ...
    
    some_sub( $_ ) for \@original, \@sorted, \@r_sorted;
    print '-';
    
  3. or download this
    some_sub( [ sort { $_ * sort_sub } @original ] ) for 0, 1, -1;
    print '-';
    
  4. or download this
    5 A B C 0 4
    0 4 5 A B C
    ...
    0 4 5 A B C
    C B A 5 4 0
    -
    
  5. or download this
    my @reversed = reverse @original;
    
    ...
    print '-';
    
    some_sub( [ sort { $_ } @original ] ) for 0, 1;
    
  6. or download this
    5 A B C 0 4
    4 0 C B A 5
    -
    5 A B C 0 4
    4 0 C B A 5
    
  7. or download this
    srand 1;
    
    ...
        
        print '';
        }
    
  8. or download this
    ===== length: 1 =====
    $key:[$a <=> $b]
    ...
    $key:[1]
     count:[59049]
     array:[9 0 4 4 5 5 0 5 1 0 ... 4 2 9 6 5 4 2 3 6 9]
    
  9. or download this
    tr/A-C/1-3/ for @original;
    
    ...
    print '-';
    
    some_sub( [ sort { $_ * ( $a + $b ) } @original ] ) for 0, 1;
    
  10. or download this
    5 1 2 3 0 4
    4 0 3 2 1 5
    -
    5 1 2 3 0 4
    4 0 3 2 1 5
    
  11. or download this
    original: 7 1 0 9 8 0 7 7 8 0
    reversed: 0 8 7 7 0 8 9 0 1 7
    $a + $b : 0 8 9 0 1 7 0 8 7 7
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-19 07:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found