in reply to stat times

     stat can't see the file it's trying to get the stats on. Put chdir($newfile) before the for loop like this

$newfile = "/perl/bin/newr"; opendir(DIR,$newfile); @files = readdir(DIR); close(DIR); chdir ($newfile); for(@files) { print "$_\n"; $filename = $_; $_ = $lastaccess = localtime ( (stat($_))[8] ); $_ = localtime ( (stat($_))[9] ); print "accs time : $lastaccess\n"; print "mod time : $_\n"; }
     While that will fix it, your code hard to read and trying to figure out what $_ is at any given time hurts my head. Please do it like this...
use strict; my $newfile = "/perl/bin/newr"; opendir(DIR,$newfile); my @files = readdir(DIR); close(DIR); chdir ($newfile) or die "Could not change to $newfile directory\n$!\n"; for(@files) { my $filename = $_; my $accesstime = localtime ( (stat($filename))[8] ); # Doing a file stat on the special _ filehandle tells # Perl to use whatever happened to be in memory from the # previous stat rather than going out to the operating # system again (Llama: 3rd Ed., p.166) my $modtime = localtime ( (stat(_))[9] ); print "file name : $filename\n"; print "accs time : $accesstime\n"; print "mod time : $modtime\n"; }

Invulnerable. Unlimited XP. Unlimited Votes. I must be...
        GhodMode

Replies are listed 'Best First'.
Re: Re: stat times
by Anonymous Monk on Aug 12, 2002 at 18:46 UTC
    Thank you for all replies and helping me!