Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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 cooling their heels in the Monastery: (4)
As of 2014-09-19 03:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls