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

Unusual sorting requirements; comparing three implementations.

by tobyink (Abbot)
on Oct 24, 2012 at 09:41 UTC ( #1000586=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @sorted = sort {
        if ($a->title =~ /Manager/ and not $b->title =~ /Manager/) {
    ...
            $a->name cmp $b->name;
        }
    } @employees;
    
  2. or download this
    my @sorted = sort {
        ($a->title !~ /Manager/) - ($b->title !~ /Manager/)
        or $a->name cmp $b->name;
    } @employees;
    
  3. or download this
    use List::MoreUtils qw( part );
    
    ...
        map  { sort { $a->name cmp $b->name } @$_ }
        part { $_->title !~ /Manager/ }
        @employees;
    
  4. or download this
    use v5.14;
    use strict;
    ...
    }
    
    done_testing();
    
  5. or download this
    use v5.14;
    use strict;
    ...
        subtle     => \&subtle,
        functional => \&functional,
    });
    
  6. or download this
    my @sorted = 
        map  { keysort { $_->name } @$_ }
        part { $_->title !~ /Manager/ }
        @employees;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1000586]
Approved by Corion
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2014-07-30 15:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (235 votes), past polls