G'day Chris,

The reason that your stat version failed was probably due to $file not existing (possibly deleted in an earlier test). The code is fine; although, I would question your use of parentheses — see the operator precedence table in perlop. Also, note that 15mins. is 900secs. but 3600 / 5 == 720 (i.e. 12 mins.): 60 * 15 would be a clearer indication of the value you want.

I'd recommend that you run some tests (similar to what I show below) which simply indicate what files are to be deleted. When you're happy everything works, then start using unlink. A backup of the directory you're working in would also be a good idea.

$ perl -Mstrict -Mwarnings -E ' my $file = q{pm_1030903.dummy}; say "(stat \$file)[9] = ", (stat $file)[9]; say "15 mins. ago = ", time - 60 * 15; if ( (stat $file)[9] < time - 60 * 15 ) { say "[stat] Will delete $file"; } say "-C \$file = ", -C $file; say "15 mins. in days = ", 60*15 / (24*60*60); if ((-C $file) > 60*15 / (24*60*60)) { say "[-C] Will delete $file"; } ' (stat $file)[9] = 1367039733 15 mins. ago = 1367041074 [stat] Will delete pm_1030903.dummy -C $file = 0.0151736111111111 15 mins. in days = 0.0104166666666667 [-C] Will delete pm_1030903.dummy

-- Ken


In reply to Re: In -X FILEHANDLE, how to derive the -C of all files in a $dir variable? by kcott
in thread In -X FILEHANDLE, how to derive the -C of all files in a $dir variable? by taint

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.