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"'
| [reply] [d/l] [select] |
my $file;
if (-M $file == 7) # -M file test op checks for last modification. Fo
+r more see Camel Book, Page 85
{
print "File is 7 days old\n";
}
It's easy, mm-kay?
Update: Bah! Arturo wins again! Eventhough, he showed how to find out if the file is greater than 7, when the question clearly asks for equal to 7. Hee Hee! (:P)
Azatoth a.k.a Captain Whiplash
Make Your Die Messages Full of Wisdom!
Get YOUR PerlMonks Stagename here!
Want to speak like a Londoner? | [reply] [d/l] |
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
| [reply] [d/l] [select] |
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. | [reply] |
| [reply] |
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.
| [reply] |
I blame my documentation -- it seemed suggest that stat was for filehandles and lstat was for filenames...
--
RatArsed
| [reply] |