That's the easy part. Now, you need to define date_larger_than, which I can think of several possibilities.my $i = 0; foreach my $href ( @array ) { last if date_larger_than( $href->{ 'date' }, $today ); $i++ } # Mark it, if you want, assuming found... if ( $i < scalar @array ) { # $array[$i]->{ 'isnext' } = 1; }
If you don't need the textual representation of the data; that is, if you can handle "20010201" as well as "2001-02-01", then you can simply use a numerical comparison, assuming that the hash's dates are changed to the numerical representation as well.
You can change them on the fly, as well:
And compare like that.my ($y, $m, $d) = ( $date =~ /(\d{4})-(\d{2})-(\d{2})/ ); $date_num = $y*10000 + $m*100 + $d;
There's numerous date classes that could probably read that date in into an object, and then use their built in date comparators to see which date is greater.
In this case , for date comparisons, there is definitely MTOWTDI.
Update - Added grouping on the regex above, oops
In reply to Re: Finding array element
by Masem
in thread Finding array element
by voyager
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |