|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
>>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 |
|
#4
|
|||
|
|||
|
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; |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Finding a file's last updated time/date |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|