my @dates = qw( 2001-12-24 1999-03-2 2004-04-23 );
print join(', ', sort { $b cmp $a } @dates );
####
2004-04-23, 2001-12-24, 1999-03-2
####
sort { $a->{date} cmp $b->{date} } @$array
####
grep { $_->{date} ge $today } ...
####
( ... )[0]->{isnext} = 1;
####
(grep {$_->{date} ge $today} sort {$a->{date}cmp $b->{date} } @$array)[0]->{isnext} = 1;
####
my $today = '2001-03-28';
my $array = [
{ date => '2001-02-01' },
{ date => '1999-04-09' },
{ date => '2001-03-31' },
{ date => '2001-03-24' },
{ date => '2001-04-15' },
];
# find the smallest date larger than or equal to today.
# set the isnext flag
(grep { $_->{date} ge $today } sort { $a->{date} cmp $b->{date} } @$array)[0]->{isnext} = 1;
# print all out and indicate which one is next...
for my $e (@$array) {
print "\n", $e->{date};
print " this is next" if $e->{isnext};
}
# alternatively :
my $thenext = (grep { $_->{date} ge $today } sort { $a->{date} cmp $b->{date} } @$array)[0];
print "\nThe next date is: $thenext->{date}\n";