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

Re: Date to be sorted in descending and time in ascending

by kcott (Chancellor)
on May 18, 2012 at 09:48 UTC ( #971257=note: print w/replies, xml ) Need Help??


in reply to Date to be sorted in descending and time in ascending

The basic technique for sorting on multiple columns in a set of records (an array of arrays) is:

my $primary_sort_column = n; my $secondary_sort_column = n; my $tertiary_sort_column = n; my @sorted_records = sort { $a->[$primary_sort_column] op $b->[$primary_sort_column]; || $a->[$secondary_sort_column] op $b->[$secondary_sort_column]; || $a->[$tertiary_sort_column] op $b->[$tertiary_sort_column]; ) @unsorted_records;

n is an integer; op is typically cmp (lexical ordering) or the spaceship operator <=> (numeric ordering)

Take a look at sort for details.

-- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://971257]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2017-05-29 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?