Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Multiple Sort on selected column

by Tanktalus (Canon)
on Oct 18, 2012 at 19:34 UTC ( #999803=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    @ranked = sort { $a->{FIRST} cmp $b->{FIRST} or $a->{LAST} cmp $b->{LA
    +ST} or $a->{AGE} <=> $b->{AGE} } @employees;
    
  2. or download this
    #!/usr/bin/perl
    
    use strict;
    ...
    foreach my $emp (@ranked) {
        print "$emp->{SALARY}\t$emp->{AGE}\t$emp->{FIRST}\t$emp->{LAST}\n"
    +;
    }
    
  3. or download this
    $ perl x.pl first age
    600000  45      Bill    Gates
    ...
    55000   29      Joe     Tester
    600000  41      Steve   Ballmer
    600000  45      Bill    Gates
    
  4. or download this
    @types{map -$_, keys %types} = map -$_, values %types;
    
  5. or download this
    my $sorter = multikeysorter( sub { my $A = $_; map { $A->{s/^-//r} } @
    +sort }, @types{@sort} );
    
  6. or download this
    $ perl5.14.2 x.pl -age last first
    600000  45      Bill    Gates
    600000  41      Steve   Ballmer
    55000   29      Sally   Developer
    55000   29      George  Tester
    55000   29      Joe     Tester
    
  7. or download this
    my $sorter = multikeysorter( sub { my $A = $_; map { (my $k = $_) =~ s
    +/^-//; $A->{$k} } @sort }, @types{@sort} );
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-07-30 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls