Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > date modified if statement

Reply
Thread Tools

date modified if statement

 
 
RedGrittyBrick
Guest
Posts: n/a
 
      10-26-2005
Purl Gurl wrote:
> RedGrittyBrick wrote:
>
>> 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>
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      10-27-2005
wrote:
> Jürgen Exner wrote:
>> wrote:
>>> 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.

>
> 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


 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      10-27-2005
A. Sinan Unur <> wrote in comp.lang.perl.misc:
> "John W. Krahn" <> wrote in
> news:ZSy7f.63594$ir4.51055@edtnps90:
> > Mothra wrote:
> >> Hi A. Sinan Unur,
> >> A. Sinan Unur wrote:


> > The /s option determines if the . character matches every character or
> > every character except newline but is isn't used so no, it is NOT
> > required.

>
> 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
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      10-27-2005
(Anno Siegel) wrote in
news:djrdas$hk7$:

> A. Sinan Unur <> wrote in comp.lang.perl.misc:
>> "John W. Krahn" <> wrote in
>> news:ZSy7f.63594$ir4.51055@edtnps90:
>> > Mothra wrote:
>> >> Hi A. Sinan Unur,
>> >> A. Sinan Unur wrote:

>
>> > The /s option determines if the . character matches every character
>> > or every character except newline but is isn't used so no, it is
>> > NOT required.

>>
>> 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.


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

--
A. Sinan Unur <>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      10-27-2005
Anno Siegel wrote:
> A. Sinan Unur <> wrote in comp.lang.perl.misc:
>>"John W. Krahn" <> wrote in
>>news:ZSy7f.63594$ir4.51055@edtnps90:
>>>Mothra wrote:
>>>>Hi A. Sinan Unur,
>>>>A. Sinan Unur wrote:

>
>>>The /s option determines if the . character matches every character or
>>>every character except newline but is isn't used so no, it is NOT
>>>required.

>>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.


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


John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      10-27-2005
"John W. Krahn" <> wrote in
news:9nb8f.48373$yS6.25290@clgrps12:

> Anno Siegel wrote:
>> A. Sinan Unur <> wrote in
>> comp.lang.perl.misc:
>>>"John W. Krahn" <> wrote in
>>>news:ZSy7f.63594$ir4.51055@edtnps90:
>>>>Mothra wrote:
>>>>>Hi A. Sinan Unur,
>>>>>A. Sinan Unur wrote:

>>
>>>>The /s option determines if the . character matches every character
>>>>or every character except newline but is isn't used so no, it is NOT
>>>>required.
>>>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.

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


In a nutshell:

http://mike.kruckenberg.com/archives...ractice_p.html

Regex

* always use the x flag for extended, broken onto separate lines with
comments
* use /m to make $ and ^ work naturally
* never use $ and ^ as string boundary, use \A and \Z
* use /s so the . will match a newline

Hope this helps.

Sinan
--
A. Sinan Unur <>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
wisefamily@integrity.com
Guest
Posts: n/a
 
      10-27-2005

Jürgen Exner wrote:
> wrote:
> > Jürgen Exner wrote:
> >> 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

 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      10-28-2005
<> wrote in comp.lang.perl.misc:
>
> Jürgen Exner wrote:
> > wrote:
> > > Jürgen Exner wrote:
> > >> 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
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
Reply With Quote
 
foo bar baz qux
Guest
Posts: n/a
 
      10-28-2005
Kiralynne Schilitubi (AKA Purl Gurl, AKA Godzilla, AKA Kira) wrote:
> RedGrittyBrick wrote:
>> Purl Gurl wrote:
>>>
>>> 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.


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?

 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      10-31-2005
Jürgen Exner wrote:
> wrote:
>
>>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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Varibly modified type in switch statement Zhang Yuan C Programming 5 01-14-2013 07:52 AM
Date last Accessed vs Date Modified Roedy Green Java 1 02-22-2008 09:41 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
software to set file modified date to exif photo taken date? Alex Hunsley Digital Photography 2 05-20-2004 10:27 AM
How does a perl script get the last-modified date of a file? Rich Pasco Perl 2 10-09-2003 07:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57