Your skill will accomplish what the force of many cannot |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
New to programming in general I take it? Often the thing to do is ask yourself "how do you do it manually?", and then have the computer do it the same way. There are usually tricks, standard algorithms and modules to do it, but at the core of it all is figuring out what steps need to be followed to accomplish a goal. How do you compare two dates manually? Myself, I do:
A convenient operator for this sort of sequence in general is <=> it returns -1, 0 or +1 depending on whether the left side is smaller,equal, or bigger than the right side. Combine that with or, which will return the left side if it is true, otherwise return the right side. (Standard boolean logic: false or true => true, false or false => false, true or anything => true) my $result = $startRange eq 'any' or $year <=> $startRangeYear or $month <=> $startRangeMonth or $day <=> $startRangeDay;Dates in particular have a nice property that lets you compare them even easier. Write the date as a number with zero padding: 20130506 and compare it to some other date given the same treatment: 20121225. Now it is trivial to see if one date is less than, equal or greater than another. my $ymd = sprintf('%04d%02d%02d', $year, $month, $day); In reply to Re^3: Perl ranges
by SuicideJunkie
|
|