How to sort dates in Perl ?

Answer Posted / kiruthikau

Try the following way.
Example
-------
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;

Is This Answer Correct ?    7 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is it meants by '$_'?

529


What does redo statement do in perl?

526


Explain goto expr?

483


Demonstrate subroutines in perl with a simple example.

464


When would `local $_' in a function ruin your day?

532






What is the use of –w?

525


What are arrays in perl?

553


You want to print the contents of an entire array. How would you do that?

519


What happens to objects lost in "unreachable" memory, such as the object returned by Ob->new() in `{ my $ap; $ap = [ Ob->new(), $ap ]; }' ?

540


Mention what is cpan?

568


How can we create perl programs in unix, windows nt, macintosh and os/2 ?

471


What does length(%HASH) produce if you have thirty-seven random keys in a newly created hash?

568


How to convert strings into an array in perl?

510


What is the main function of cookie server?

520


How to connect to SQL server through Perl?

556