#!C:/Perl/bin -w use strict; use vars qw ( @old $old %data $sec $min $hour $mday $mon $year $etime ); use Time::Local qw (timelocal); # create hash to hold filename and $etime with a fake key # and value -- both to be deleted after the foreach on DATA %data = ( "file", 0 ); @old = ; foreach $old(@old) { if ( $old =~ / # 1 of many ways. For clarity, not elegance ^ # start at beginning of line [MTWFS] # Any one UpperCase first_letter_of_day_of_week (english) [a-z]{2} # Any lowercase letter, 2 times exactly \s # One whitespace char ([A-Za-z]{3}) # UC or lc in range A-Z or a-z, 3 times -- CAPTURE month $1 \s # One whitespace char ([\d]{1,2}) # one or two digits - day_of_month -- capture day_of_month $2 \s # One whitespace char ([\d]{1,2}): # Any dec dgt or :, 1 OR 2 times -- CAPTURE Hour $3 - fol by : ([\d]{2}): # Any dec dgt or :, 2 times -- CAPTURE Min $4- fol by : ([\d]{2})\s # Any dec dgt or :, 2 times -- CAPTURE Sec $5 - fol by sp [ECMP][SD]T # Eastern, Central...Std or Day...T \s # One whitespace (200\d) # One whitespace fol by "200" and 1 more dgt CAPTURE Yr $6 .* /x # anything_except_\n to end_of_record, end m//, extended syntax ) # end condition { # begin action block $sec = $5; $min = $4; $hour = $3; $mday = ( $2 - 1 ); # mday is in range 0-30 for timelocal $mon = $1; # needs to be in 0..11 form: &convert_month $year = $6; # ?! timelocal years are years - 1900 &cvrt_mon_lcl($mon); # etime from $old form to Epoch seconds $etime = timelocal($sec, $min, $hour, $mday, $mon, $year); chomp ($old); # clean \n off $old. $old =~ s/is : / /; # shorten to DateTime:depth # print "\$etime for \"$old\"|| \t$etime\n"; $data{$old}= $etime; # PUSH etime to the hash } else { print "no match \n"; } } # NOW, delete the (fake) elements with which we initialized the hash delete $data{"file"}; # NEXT convert current time to seconds since EPOCH my $now = time(); # ASSESS the DATA elements for > or < 45 days old while (($old, $etime) = each %data) { if ( ($now - $etime) > (24*60*60*45) ) { # 24hr*60min*60sec*45 days print " \"$old\" - is MORE than 45 days old\n"; print "\t It's roughly ".int(($now-$etime)/86400)." days old\n\n"; } else { # This errs in favor of "LESS THAN" (no == test above) print " \"$old\" - is LESS than 45 days old\n"; print "\t It's only about ".int(($now-$etime)/86400)." days old\n\n"; } } exit; ##### sub cvrt_mon_lcl -- FOR timelocal and localtime; gmtime is different! sub cvrt_mon_lcl { if ($mon eq "Dec") { $mon = 11; }elsif ($mon eq "Nov") { $mon = 10; }elsif ($mon eq "Oct") { $mon = 9; }elsif ($mon eq "Sep") { $mon = 8; }elsif ($mon eq "Aug") { $mon = 7; }elsif ($mon eq "Jul") { $mon = 6; }elsif ($mon eq "Jun") { $mon = 5; }elsif ($mon eq "May") { $mon = 4; }elsif ($mon eq "Apr") { $mon = 3; }elsif ($mon eq "Mar") { $mon = 2; }elsif ($mon eq "Feb") { $mon = 1; }elsif ($mon eq "Jan") { $mon = 0; } return($mon); }