> -----Original Message-----
> From: ZHAO, BING [mailto:[EMAIL PROTECTED]
> Sent: Monday, October 10, 2005 4:48 PM
> To: Perl Beginners List
> Subject: keeping track of the 'age' of a file
> 
> Hi,
>                Sorry I have to ask random questions again, perl is so
> profoud and I just finished
> reading the Llama book, and deeply feel like doing crazy things but
> couldn't  but still believe
> perl could do it and believe one of you guys could enlighten
me..........
>                 No more blah.
>                 I am doing this CGI upload website, by saving files
> submitted by other people,
> (there is no problem with the storage capacity), I can readily delete
the
> file right after all the
> processing/modification on it is done. But, I figured it might be a
good
> idea to save the file for
> like a week then delete it, if I know some kind of function like
> "clock"(as wild as it can get..),

If you read the Llama book, you'd be familiar with the stat() function:

use warnings;
use strict;

my $secInAWeek = "604800";
my $now = time;
my $file = "someFile.ext";
my ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
$mtime, $ctime, $blksize, $blocks ) = stat($file);
my $age = $now - $ctime;

if ( $age > $secInAWeek ) {
  # the file is older than a week
  unlink $file or die "Unable to delete $file: $!\n";
}

See perldoc -f stat for more information.

ry

> "date" etc, so after a week or so, the perl script would delete the
file.
>                  If you think this is something too crazy, don't
hesitate
> to throw me the words,"
> put it out, you idiot!", " are you nuts?" or whatever you feel like
saying
> to me, then I will know
> "hm, maybe I have to resolve it in another way...."
>                  thank you all.
> 
> best,
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to