in reply to Finding array element
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Finding array element
by chromatic (Archbishop) on Mar 28, 2001 at 23:08 UTC | |
|
Re: Re: Finding array element
by Vondikall (Initiate) on Mar 29, 2001 at 17:04 UTC | |
|
Re: Re: Finding array element
by voyager (Friar) on Mar 28, 2001 at 23:05 UTC |