I'm having trouble using "$fileAge = -M $fileName" to determine age of files in a directory. Basically, I need to see if all the files in a directory are more than a day old. If they are, I process them. My problem is that whenever the fileAge is printed out, it's null and looks like this: "Filename=[result.896] file age = []" I should add that all the files I'm currently scanning are less than a day old for now. What am I doing wrong?

# Test output files for age to see if they should be processed # Start out assuming all output files may be parsed my $filesAreOldEnough = 1; if ( $numOutputFiles > 0 ) { foreach my $fileName ( @outputFiles ) { my $fileAge = -M $fileName; print "Filename=[ $fileName ] file age = [ $fileAge ]\n"; if ( $fileAge < 1 ) { $filesAreOldEnough = 0; #last; # check all files for now } } } else { # No input files to process, skip directory... $filesAreOldEnough = 0; }

edited by ybiC: URL-escaped square brackets in text


In reply to Using -M to test age of file by bwelch

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.