Hello Experts,
#! /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


In reply to Month '-1' out of range 0..11 by swissknife

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.