#! /usr/bin/perl use strict; use Time::Local; use Math::BigFloat; Math::BigFloat->precision(0); my $inpath = "/tmp/IN"; my @inputfiles = &GetINDirFiles($inpath); print "@inputfiles \n"; sub GetINDirFiles { my ($path) = @_; my $min_age = 0.25/24; opendir DIR, $path or die $!; # my @files = readdir DIR; my @files=grep {!/\_ACK|_\d+_\d+\.xml/ && (&UTCtoLocal("$path/$_")) } readdir DIR; closedir DIR; return(@files); } sub UTCtoLocal { my ($filetoread) = @_; open (INFILE, "<$filetoread") or die "$!"; my @ActTime = map {/"(.*?)"/} grep {/MessageDateTime/} (); my $iso_time = join("", @ActTime); my $expected_epoch = 1 * 60 * 60 + 1 * 60 + 1; my ($date, $time) = split /T/ => $iso_time; my ($year, $mon, $mday) = split /-/ => $date; my $currenttime = time; # get current time from system (epoch time) my $threshold = 900; $year -= 1900; $mon -= 1; my ($hour, $min, $sec) = split /:/ => $time; my $nsec = chop($sec); my $mtime = timegm($sec, $min, $hour, $mday, $mon, $year); my $diff = ($currenttime - $mtime); if ($diff > $threshold) { return ($filetoread); } }