#!/user/bin/perl use warnings; use strict; my @dates = ( '01-31 01:33', '01-30 22:10', '01-12 05:59', '01-02 01:33', '01-24 01:42', '01-12 05:56', ); print "The dates to be sorted are:\n"; my $numDates = scalar(@dates); my $colCount = 0; for(my $i = 0; $i < $numDates; $i++){ $colCount++; if($colCount > 3){ $colCount = 1; print "\n"; } # end if print " $dates[$i]"; } # end for $i loop print "\n"; my @sortedDates = sort mySort @dates; print "The sorted dates are:\n"; $numDates = scalar(@dates); $colCount = 0; for(my $i = 0; $i < $numDates; $i++){ $colCount++; if($colCount > 3){ $colCount = 1; print "\n"; } # end if print " $dates[$i]"; } # end for $i loop print "\n"; exit(0); sub mySort { my($part1a,$part2a) = split(/\s+/,$a); my($part1b,$part2b) = split(/\s+/,$b); my($mon_a,$day_a) = split(/-/,$part1a); my($mon_b,$day_b) = split(/-/,$part1b); my($hr_a,$min_a) = split(/:/,$part2a); my($hr_b,$min_b) = split(/:/,$part2b); return 0 if($a eq $b); if($mon_a == $mon_b) { if($day_a == $day_b) { if($hr_a == $hr_b) { return ($min_a <=> $min_b); } elsif($hr_a < $hr_b) { return -1; } else { return 1; } } elsif($day_a < $day_b) { return -1; } else { return 1; } } elsif($mon_a < $mon_b) { return -1; } else { return 1; } } # end sub mySort()