Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 7th, 2000, 11:25 AM
Adrian2 Adrian2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: London, England
Posts: 251 Adrian2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
I want to be able to read the timestamp on a file from Perl.

I'm writing a CGI script to run from a SSI that indicates whether a webcam is on or not. So I'm going to do this by checking the timestamp of the last uploaded file and seeing whether it's recent enough.

This sounds simple enough but I have read and read and can't find the answer.

Any help greatly appreciated.

Reply With Quote
  #2  
Old August 7th, 2000, 12:20 PM
goBoating goBoating is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Charleston, SC, USA
Posts: 10 goBoating User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
try 'stat'...... like

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
@details = stat aTextFile;
$modifyTime = $details[9];
[/code]


'hope this helps

Reply With Quote
  #3  
Old August 7th, 2000, 03:20 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>try 'stat'...... like

This would be the easiest and cleanest. If you want to break the date down to a few pieces, try this instead -> http://www.devshed.com/Talk/Forums/Forum6/HTML/000254.html

Reply With Quote
  #4  
Old August 7th, 2000, 05:44 PM
Adrian2 Adrian2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: London, England
Posts: 251 Adrian2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
Thanks for all your suggestions.

In the end I used -M to determine the relative time in days since the file was last modified. I did this because as I only want to know whether the file is more than a certain amount old it's easier to work with a value that's already relative rather than make a calculation based on the current time.

Here's my code that I embed from a server side include:

#!/usr/bin/perl

# Checks whether a file has been recently updated
# used to determine whether a webcam is "on"

$FILENAME = 'livepic.jpg'; # name of file you want to check
$REFRESH = 300; # camera refresh in seconds (eg. 5 minutes)

$ON_TEXT = "<p>The camera is <b>on</b>.";
$OFF_TEXT = "<p>The camera is <b>off</b>.";

$SECOND = 1 / 24 / 60 / 60; # calculate 1 second as a fraction of 1 day

print "Content-type: text/htmlnn";

if ( (-M $FILENAME) > $REFRESH * $SECOND ) {
print "$OFF_TEXT";
} else {
print "$ON_TEXT";
}

exit;

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Finding a file's last updated time/date

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap