Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: file date
by arturo (Vicar) on Jun 11, 2001 at 19:44 UTC
    if ( -M $filename > 7) [ # do something }

    See perlfunc:_X or perldoc -f -X for more information.

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
Re: file date
by azatoth (Curate) on Jun 11, 2001 at 19:46 UTC
      azatoth is technically correct, but remember that -M doesn't output integers. An example from my box:
      $ perl -e 'print -M $ARGV[0], "\n"' foo.pl 21.7745138888889
      So, -M $file == 7 is true if and only if the file was created precisely 168 hours ago. :) (Excluding leapyears, etc.) So it's better to use the greater-than sign. If for some (unfathomable-to-me) reason you want files that were created seven days ago but not those create more than seven days ago, use int( -M $file ) == 7.

      Trying to compare integers with floating-point numbers can be confusing, since there's rarely an exact match.

      stephen

Re: file date
by Beatnik (Parson) on Jun 11, 2001 at 21:53 UTC
    A pretty similar thread is Display A File Via Attribute, which is only a 'few days' old :)

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: file date
by RatArsed (Monk) on Jun 11, 2001 at 19:52 UTC
      Have you? :) lstat is a stat for symbolic links, which are not always available on platforms... stat would be cleanest, altho -X's -M would be ok too :)

      Yes, I know that if lstat is not available, a plain stat is used :)

      Greetz
      Beatnik
      ... Quidquid perl dictum sit, altum viditur.
        I blame my documentation -- it seemed suggest that stat was for filehandles and lstat was for filenames...

        --
        RatArsed