Convert the dates to a numerical, fixed-width, greatest significance first format. For instance, if you have Feb 12, 06, you could translate that to 060112, then compare numerically:
use strict;
use warnings;
my $date1 = dateconvert('Jan 11, 04');
my $date2 = dateconvert('Jan 30, 04');
my $date3 = dateconvert('Feb 10, 04');
print "$date1 <= $date2 <= $date3 ? ";
print $date1 <= $date2 && $date2 <= $date3 ? "Yes" : "No";
BEGIN {
my @mon = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
my %mon; $mon{$mon[$_]} = $_ for 0..$#mon;
sub dateconvert {
my $date = $_[0];
my ($mon, $day, $year) = $date =~ m/(\w+) (\d+), (\d+)/;
$mon = $mon{$mon};
return sprintf("%02d%02d%02d", $year, $mon, $day);
}
}
This is easily modified for different formats by changing a couple lines in the function.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|