Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by kcott (Abbot)
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


Comment on Re: Date to be sorted in descending and time in ascending
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (13)
As of 2015-07-31 19:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (280 votes), past polls