Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: file date

by azatoth (Curate)
on Jun 11, 2001 at 19:46 UTC ( [id://87546]=note: print w/replies, xml ) Need Help??


in reply to file date

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?

Replies are listed 'Best First'.
(stephen) Re: Re: file date
by stephen (Priest) on Jun 11, 2001 at 22:15 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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://87546]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-19 08:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found