Hi Monks,
This is crazy but I can't figure this one out. This time all I am trying to do is print the age of the session files found in a directory. Why is the time been displayed is the same for all the files, and how would I format the results to be readable in hours, minutes etc.
Here is my nightmare code,and the time been printed is not correct for these files as well. Any help please, or a better way to get get the age of files in hours,minutes etc, will be very helpful!
#!/usr/bin/perl -w
use strict;
use CGI qw(-oldstyle_urls :standard);
use CGI::Carp qw(fatalsToBrowser);
use File::Find;
use File::stat;
my $mytime=(time);
my $file_stat;
my $all_session = "../sessions";
print header();
print qq(<br><br><table width="600" border="1" bgcolor="#808080" cellp
+adding="2" cellspacing="0">
<tr><form action="wacko_del_old_files.pl" method="post" style
+="margin: 0px; padding: 0px;">
<td align="left" colspan=\"2\"> Sessions.</td>
</tr>
<tr><td align="left" colspan=\"2\"> </td></tr>);
opendir(DIR, $all_session) or die "Couldn't open directory, $!";
while (my $sessions = readdir DIR) {
# Use a regular expression to ignore files beginning with a peri
+od
next if ($sessions =~ m/^\./);
my $age = (time() - (stat("$all_session/$sessions"))[10]);
print "<tr>
<td align=\"left\"> $sessions - age= $age</td>
<td align=\"left\"> <input type=\"checkbox\" name=
+\"del_sessions\" value=\"$sessions\"> </td>
</tr>";
}
closedir DIR;
print "<tr>
<td colspan=\"2\" align=\"right\"> <td><input type=\"s
+ubmit\" value=\"Delete\"></td></td>
</tr></form>
</table>";
Thanks for looking!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.