date modified if statement

R

RedGrittyBrick

Purl said:
RedGrittyBrick said:
Naji wrote:

(snipped)

if ((time - (stat 'filename')[9]) < 24*60*60) {
print "recently modified/n";
}


Both you and readers will be as surprised as I by benchmark results.

You are wrong, after years of your peculiar postings I'm hardly
surprised by anything you might post, however surreal.

Most people would understand that the reason I used "time" and
"24*60*60" were to make comprehension easy for Naji who is "rather new
to Perl".

Unless you are an obsessive, normal priorities are:
1) Make it produce correct results.
2) If performance is a problem, optimise.
Initially, I became curious if use of time and multiplication would
be less efficient than use of $^T and 86400 to compare Epoch seconds.
Test results don't disclose this but rather a real surprise related to use
of Perl's default time function.

Purl Gurl

I plugged these codes into benchmark:

sub Time
{
timethese (100000,

It is very unlikely that Naji has 100,000 attachments that need
monitoring so tweaking performance seems a bit overkill at this stage.
Even if he did have that many, 13 elapsed seconds for 100,000 tests
wouldn't be worth worrying about for the purposes he describes.
{
'Brick' =>
'if (time > 24*60*60)
{ $out1 = "true"; } ',

The statement 'if (time > 24*60*60) ...' bears so little relation to my
code or any useful code that I wonder why anyone might think it
worthwhile to benchmark it. time() has been greater than 24*60*60 since
before Perl existed!

I rather suspect that you took out the stat() simply because in real
world code, the time to perform stat() swamps everything else. This
makes the benchmark pretty futile in my view.

Your code reminds me of people who tried to benchmark
for i=1 to 100,000
end for
only to find the compiler had optimised it to
NOP

Generally I trust compilers to do obvious optimisation for me.

As a general principle, I usually consider slow clear code to be
'better' than fast obfuscated code.

<snip: useless benchmark of purposeless code>
 
J

Jürgen Exner

Jürgen Exner said:
I was about to suggest the same when i double checked the
documentation:

-M Age of file in days when script started.
-A Same for access time.
-C Same for inode change time.

This is a confusing file test. There is some documentation that says
that -M is the age, others say that it is the modification date.
However, from what I noticed, there is more documentation that says it
is the modification date. [lenghty test snipped]
The test makes me think that the -M test returns the modification
date.

Problem is: different file systems keep track of different 'dates' and not
all dates (creation, modification, access, ...) are available on all file
systems.
Therefore you should be careful when using the results of -X as well as
stat() when dates are involved. Your code may be testing something different
on a different file system

jue
 
A

Anno Siegel

A. Sinan Unur said:
True. It was a little brainless typing on my part.

....unless you follow _Perl Best Practices_, which suggests using /xms on
all regexes, needed or not. I'm not following it there, at least not
yet.

Anno
 
A

A. Sinan Unur

(e-mail address removed)-berlin.de (Anno Siegel) wrote in
...unless you follow _Perl Best Practices_, which suggests using /xms
on all regexes, needed or not. I'm not following it there, at least
not yet.

You are very insightful.

Well, it was brainless because I was trying to get used to following
PBP, and just put it in there without thinking about it :)

Sinan
 
J

John W. Krahn

Anno said:
...unless you follow _Perl Best Practices_, which suggests using /xms on
all regexes, needed or not. I'm not following it there, at least not
yet.

I don't have the book. What is Damian's justification for this?


John
 
W

wisefamily

Jürgen Exner said:
Jürgen Exner said:
(e-mail address removed) wrote:
I think that syntax would be like this (assuming you have the
attachment name in the variable $attachment):

if(-M $attachment <= 0.5) {

This is a confusing file test. There is some documentation that says
that -M is the age, others say that it is the modification date. [lenghty test snipped]
The test makes me think that the -M test returns the modification
date.

Problem is: different file systems keep track of different 'dates' and not
all dates (creation, modification, access, ...) are available on all file
systems.
Therefore you should be careful when using the results of -X as well as
stat() when dates are involved. Your code may be testing something different
on a different file system

You may be right-but would perl have a file test that returns two
unrelated statistics on different file systems? If a file system
doesn't keep track of the modification date, would perl really return
the age of the file?

David
 
A

Anno Siegel

Jürgen Exner said:
Jürgen Exner wrote:
(e-mail address removed) wrote:
I think that syntax would be like this (assuming you have the
attachment name in the variable $attachment):

if(-M $attachment <= 0.5) {

This is a confusing file test. There is some documentation that says
that -M is the age, others say that it is the modification date. [lenghty test snipped]
The test makes me think that the -M test returns the modification
date.

Problem is: different file systems keep track of different 'dates' and not
all dates (creation, modification, access, ...) are available on all file
systems.
Therefore you should be careful when using the results of -X as well as
stat() when dates are involved. Your code may be testing something different
on a different file system

You may be right-but would perl have a file test that returns two
unrelated statistics on different file systems? If a file system
doesn't keep track of the modification date, would perl really return
the age of the file?

It might. If a file system was to report the creation date where standard
file systems report the modification date, how is Perl to know?

Someone human would have to notice the discrepancy and write extra code
for the special case.

Anno
 
F

foo bar baz qux

Peculiar? Surreal?
over these many years regulars in this group have directed at me,
insults, racial slurs, threats of physical violence, threats of death, have
tried a million times to crash my server and, of course, troll me everyday
I am here, not to mention behaviors too abhorrent to mention, some so
abhorrent a need came about to contact law enforcement. I'm still
standing and they are still the timeless fools hoping to someday stand
and walk like a man.

QED!


PG omitted any mention of the pointlessness of the benchmark which PG
posted. Too painful for PG's over-inflated self-regard?
 
J

Joe Smith

Jürgen Exner said:
Naji wrote:
[...]
every time the attachment is updated. What would the syntax be for
the if statement for code that would send the attachment if it has
been modified in the past 12 hours? Any help would be appreciated.
Thanks!

I think that syntax would be like this (assuming you have the
attachment name in the variable $attachment):

if(-M $attachment <= 0.5) {

I was about to suggest the same when i double checked the documentation:

-M Age of file in days when script started.
-A Same for access time.
-C Same for inode change time.

Unfortunately there is no -X file test for modified time. If you really want
modified time then you are stuck with stat().

That is incorrect. The documentation is misleading and/or incomplete.
-A uses stat[8] for access time.
-M uses stat[9] for modification time.
-C uses stat[10] for change time.

-M is like ($^T-(stat _)[9])/(24*60*60).

-Joe
 
J

Joe Smith

Naji said:
test for files that have been modified in the last 12 hours?

perl -MFile::Find -le 'find(sub {print $File::Find::name if -M $_ <
0.5},@ARGV)' /tmp /var/tmp /home/joe/Mail

-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top