Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Need Script Help - file/time diff in seconds
I have code that returns the most recent modified file in a directory
(Win2K/Apache/PERL).  I want to compare the modified time on that filename
that is returned ($newestFile) to the local time on the webserver and spawn
a failure response if the difference in time is more than 600 seconds (10
minutes).  I've looked everywhere for examples are am totally  by
the whole epoch time, time conversion etc.  Please help.  Thanks - joe

use POSIX;
use File::Find;
use File::Stat;
use Date::Manip;
$folder = 'D:\wxc\data\radar\national\nat1km';
@files = grep {-f} glob "$folder/*";
$fNT{$_} = sprintf "%010d", (stat $_)[9] for @files;#create hash with file
and file last modified date
$newestFile = ( sort {$fNT{$b} <=> $fNT{$a}} keys %fNT )[0];#the first
element of the sorted hash
print $newestFile;
$file = $newestFile;
$mtime = (stat $file)[9];
print strftime("%A %B %d, %Y %H:%M %p", localtime($mtime));
print strftime("%A %B %d, %Y %H:%M %p", localtime(time));




Report this thread to moderator Post Follow-up to this message
Old Post
Willie Nelson
08-20-04 02:11 AM


Re: Need Script Help - file/time diff in seconds
Willie Nelson wrote:
> I have code that returns the most recent modified file in a
> directory (Win2K/Apache/PERL).  I want to compare the modified time
> on that filename that is returned ($newestFile) to the local time
> on the webserver and spawn a failure response if the difference in
> time is more than 600 seconds (10 minutes).  I've looked everywhere
> for examples are am totally  by the whole epoch time, time
> conversion etc.

Everywhere? Did your research include the Perl documentation, for
instance the description of the stat() and time() functions?

perldoc -f stat
perldoc -f time

It's obvious that you didn't wrote the script yourself, but you
probably just picked it up somewhere and now you are asking this group
to modify it for you. It's not advisable to use random pieces of code
without understanding how it works, so I'd suggest that you start there.

As regards your question, you should be able to write the condition
using the $mtime value (as given from the script) and the return value
from time().

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Report this thread to moderator Post Follow-up to this message
Old Post
Gunnar Hjalmarsson
08-20-04 02:11 AM


Re: Need Script Help - file/time diff in seconds
Thanks for the response.  FYI, this is one of those learn as you go
projects.  Now that I'm seeing the flexibility of PERL, I plan on using it
for more things.

I have checked the PERL docs, but this whole epoch time thing is killing me.
I've created the following at the end of the script:

$seconds_diff = int($time - $mtime);

but all it does is return the same result:  -1092926507.  I know that I'm
close here, but just can't get over the hump.  Any suggestions?

Thanks,
joe



Report this thread to moderator Post Follow-up to this message
Old Post
Willie Nelson
08-20-04 02:11 AM


Re: Need Script Help - file/time diff in seconds
Ok.  This is the string that I need.  The value changed when my newest file
was updated.  Now the question is turning that large number into a value for
seconds or minutes.  Any suggestions?

Thanks,
joe

"Willie Nelson" <willie@buymyrecords.com> wrote in message
news:u%2Vc.95$Ae.73@newsread1.dllstx09.us.to.verio.net...
> Thanks for the response.  FYI, this is one of those learn as you go
> projects.  Now that I'm seeing the flexibility of PERL, I plan on using it
> for more things.
>
> I have checked the PERL docs, but this whole epoch time thing is killing
me.
> I've created the following at the end of the script:
>
> $seconds_diff = int($time - $mtime);
>
> but all it does is return the same result:  -1092926507.  I know that I'm
> close here, but just can't get over the hump.  Any suggestions?
>
> Thanks,
> joe
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Willie Nelson
08-20-04 02:11 AM


Re: Need Script Help - file/time diff in seconds
Willie Nelson wrote:
> Thanks for the response.  FYI, this is one of those learn as you go
> projects.  Now that I'm seeing the flexibility of PERL, I plan on
> using it for more things.
>
> I have checked the PERL docs, but this whole epoch time thing is
> killing me. I've created the following at the end of the script:
>
> $seconds_diff = int($time - $mtime);
----------------------^

You didn't populate any $time variable, did you? You need to use the
time() *function*. Try removing that '$' character, and you don't need
the int() function either:

$seconds_diff = time - $mtime;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Report this thread to moderator Post Follow-up to this message
Old Post
Gunnar Hjalmarsson
08-20-04 02:11 AM


Re: Need Script Help - file/time diff in seconds
Thanks!  That did the trick.  I knew it was a matter of syntax, just wasn't
sure where..

-joe

"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:2ojv97Fbkc7kU1@uni-berlin.de...
> Willie Nelson wrote: 
> ----------------------^
>
> You didn't populate any $time variable, did you? You need to use the
> time() *function*. Try removing that '$' character, and you don't need
> the int() function either:
>
>      $seconds_diff = time - $mtime;
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl



Report this thread to moderator Post Follow-up to this message
Old Post
Willie Nelson
08-20-04 02:11 AM


Re: Need Script Help - file/time diff in seconds
Willie Nelson wrote:
> I knew it was a matter of syntax, just wasn't sure where..

Yes, it was, and if you are going to learn Perl, please make it a
habit from the start to include

use strict;
use warnings;

in the beginning of every program. If that had been the case with the
script you now have modified, Perl would have helped you detect the
problem.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Report this thread to moderator Post Follow-up to this message
Old Post
Gunnar Hjalmarsson
08-20-04 02:11 AM


Re: Need Script Help - file/time diff in seconds
Willie Nelson wrote:

> I have code that returns the most recent modified file in a directory
> (Win2K/Apache/PERL).  I want to compare the modified time on that filename
> that is returned ($newestFile) to the local time on the webserver

$_ = -M "myfile";
printf "Age is %.2f days; %.2f hours; %.2f minutes\n",$_,$_*60,$_*60*60;

Age is 0.47 days; 27.96 hours; 1677.67 minutes

-Joe

Report this thread to moderator Post Follow-up to this message
Old Post
Joe Smith
08-20-04 02:11 AM


Re: Need Script Help - file/time diff in seconds
Thanks Joe.  That will help too..
-joe
"Joe Smith" <Joe.Smith@inwap.com> wrote in message
news:e86Vc.39159$mD.3798@attbi_s02...
> Willie Nelson wrote:
> 
filename 
>
> $_ = -M "myfile";
> printf "Age is %.2f days; %.2f hours; %.2f minutes\n",$_,$_*60,$_*60*60;
>
> Age is 0.47 days; 27.96 hours; 1677.67 minutes
>
> -Joe



Report this thread to moderator Post Follow-up to this message
Old Post
Willie Nelson
08-20-04 02:11 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:46 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.