use Time::Local; use constant MAX_AGE => 20; # Other code here sub older_than_MAX_AGE { my $date = _convert_date( $_[0] ); # convert yymmdd to epoch seconds my $max_epoch_seconds = MAX_AGE * 60 * 60 * 24; # MAX_AGE should be days. This converts it to seconds. my ( $day, $month, $year ) = (localtime)[3..5]; $year += 1900; my $today = timelocal( 0,0,0, $day, $month, $year ); my $cutoff_date = $today - $max_epoch_seconds; return $date < $cutoff_date ? 1 : 0 ; } sub _convert_date { # This takes a date in YYMMDD format and converts it to epoch seconds (assumes 12:00:00 midnight) my $date = shift; my ( $year, $month, $day ) = ( $date =~ /(\d\d)(\d\d)(\d\d)/ ); $year += 2000; timelocal( 0,0,0,$day,$month,$year ); }