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 tobyink (Abbot)
on May 18, 2012 at 17:02 UTC ( #971340=note: print w/ replies, xml ) Need Help??


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

Sort::Key is pretty awesome for this kind of thing.

use 5.010; use strict; use Sort::Key qw(multikeysorter); my $sorter = multikeysorter( sub { /^(.{8})(.{6})/ }, # how to split into keys qw( -int int ), # how to sort each key ); my @dateArray = grep { 1+chomp } <DATA>; say for $sorter->(@dateArray); __DATA__ 20010405000000 20050405005000 20020405081200 20080405022500 20080405022600 20080405023500 20090405022500 20090405022300 20090405022900 20090405022100
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: Date to be sorted in descending and time in ascending
Download Code
Re^2: Date to be sorted in descending and time in ascending
by salva (Monsignor) on May 18, 2012 at 17:28 UTC
    or...
    use Sort::Key::Maker sort_dates => sub { /(.{8})(.{6})/ }, qw(-int int +); my @sorted = sort_dates(@dateArray);

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (17)
As of 2014-07-30 20:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (240 votes), past polls