fork download
  1. #!/usr/bin/perl
  2. # your code goes here
  3. use strict;
  4. use warnings;
  5. my @dates = ( '2013-Dec', '2014-May', '1992-July', '2014-Jan' );
  6. my @sorted_dates = sort { (split /\-/, $a)[0] <=> (split /\-/, $b)[0] ||
  7. (split /\-/, $a)[1] cmp (split /\-/, $b)[1]
  8. } @dates;
  9. print "Latest date is ".$sorted_dates[-1]. " index is $#sorted_dates";
  10.  
Success #stdin #stdout 0s 3740KB
stdin
Standard input is empty
stdout
Latest date is 2014-May index is 3