jettero - Of course! I consider all sorts of options except for the obvious. If hold on to the value then I don't have to call stat() again.

Fletch - Thanks. I didn't know about the _ filehandle. It will probably be very efficient to check stat(_) since it is already present and being populated behind the secenes anyway.

I'll go benchmark these two approaches and see if there is any extra overhead to accessing _ with stat() versus keeping and populating my own scalar.

EDIT: Benchmarking shows that there is very little difference between the two methods. The only significant finding was that any method using one call (storing the timestamp to a scalar, stat()ing the auto-populated _ filehandle or even my original warning-prone check) is roughly twice as fast as stat()ing twice to check for existance then for a new timestamp.

With enough effort I was able to measure that storing to a scalar is about 1.5% faster than calling stat() on _. The warning-prone check is less than half a percent faster than that when the config file always exists and is about 5% slower when the config file is missing (even with STDERR closed so warnings don't go anywhere).

Bottom line: For my purposes the simplest/most direct method of storing the timestamp to a scalar then checking for definedness then difference is the most efficient method that shouldn't throw warnings. Thanks again.


In reply to Re: Most efficient File Modified check (w/o warnings) by Cefu
in thread Most efficient File Modified check (w/o warnings) by Cefu

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.