swissknife has asked for the wisdom of the Perl Monks concerning the following question:
#! /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/} (<INFILE>); 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); } }
What i am trying to achieve here is list all the files from directory /tmp/IN which does node have _ACK in the name (which is no issue) and next read the file and look for a value of MessageDateTime (This is how it appears in file <MessageDateTime v="2014-03-18T15:41:14Z" />) and if this time is 15 minute less from current time, list only such files
.When i execute it gives me below error.
Month '-1' out of range 0..11 at listfiletest.pl line 39
Could someone let me know where i am doing wrong? swissknife
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Month '-1' out of range 0..11
by Limbic~Region (Chancellor) on Mar 18, 2014 at 15:32 UTC | |
by swissknife (Sexton) on Mar 18, 2014 at 16:54 UTC | |
by Limbic~Region (Chancellor) on Mar 18, 2014 at 17:13 UTC | |
by swissknife (Sexton) on Mar 19, 2014 at 10:34 UTC | |
|
Re: Month '-1' out of range 0..11
by kennethk (Abbot) on Mar 18, 2014 at 15:32 UTC | |
by swissknife (Sexton) on Mar 18, 2014 at 15:49 UTC | |
by kennethk (Abbot) on Mar 18, 2014 at 15:57 UTC | |
by swissknife (Sexton) on Mar 18, 2014 at 16:14 UTC | |
by kennethk (Abbot) on Mar 18, 2014 at 16:26 UTC | |
by swissknife (Sexton) on Mar 18, 2014 at 16:35 UTC | |
|
Re: Month '-1' out of range 0..11
by t_rex_joe (Sexton) on Mar 18, 2014 at 17:42 UTC |