CGI Perl Question:
Download Job Interview Questions and Answers PDF
How to sort dates in Perl?
Answers:
Answer #1Example
-------
use Data::Dumper;
my @dates = ( "02/11/2009" , "20/12/2001" , "21/11/2010" ) ;
@dates = sort { join( '', (split '/', $a)[2,1,0] ) cmp
join( '', (split '/', $b)[2,1,0]) } @dates;
print Dumper \@dates;
-------
use Data::Dumper;
my @dates = ( "02/11/2009" , "20/12/2001" , "21/11/2010" ) ;
@dates = sort { join( '', (split '/', $a)[2,1,0] ) cmp
join( '', (split '/', $b)[2,1,0]) } @dates;
print Dumper \@dates;
Answer #2@sortDates = sort { join(\\'\\',(split\\'/\\',$a)[2,1,0] ) <=> join(\\'\\',(split\\'/\\',$b)[2,1,0])} @mydates;
Download CGI Perl Interview Questions And Answers
PDF