Hello everyone, I was wondering if someone could please help as I am stuck with the following problem. I have this piece of code which I created to test the part that is not working properly. What I am trying to do is search for files in a directory and do something with them if they are older than xx amount of time. In the example below I am using the check of files that are > 3 minutes. The problem that I have come across or think what the problem is, is that if the file does not meet the -M "$path" > .0020 it will never match, since I am guessing that the check is done against the time the script was launched. So when the script goes to sleep to wait for the files to be xx amount of minutes old before doing something with them it never matches, even though the xx time has gone by making them xx minutes older. Is there anyway to reset the timer of -M or is there a better way to do this? thanks for the help in advance.
#!/usr/bin/perl use strict; use warnings; my $DirPath = "/tmp//testing"; while ("true") { opendir (DIR, "$DirPath") or die "Cannot open $DirPath $!\n"; my @Files = grep { !/^\.{1,2}$/ } readdir DIR; close DIR; if(scalar(@Files) > 1) { foreach my $File (@Files) { next unless (-f "$DirPath/$File"); chomp $File; print $File, "\n"; if ((-M "$DirPath/$File" > .0020)) { print "File: $File is older than 3 minutes\n"; } else { print "File: $File is not older than 3 minutes\n"; } } } else { print "Num of file required not met\n"; sleep 10; } }

In reply to Resseting perl -M file mod after xx minutes by learningperl01

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.