Click to See Complete Forum and Search --> : Can't call method "ctime" on an undefined value at C:\books\test.pl line 17.


msg12344321
06-07-2006, 07:50 PM
Hi,
I am getting this error when calling stat more than once. My scrip searches a folder for files with a specific name (Test_result*.txt). For each of the returned file names, I would like to get the ctime. I call stat($resultfilename). However, i get similar error message as this:
"Can't call method "ctime" on an undefined value at C:\books\test.pl line 17."

The following script is getting the same error on the second stat call:

-----------------------------------------------
use File::stat;

$latestfile = "asdfasdfasdfasdf_test.txt";

$latestfile_stat = stat($latestfile);
$temp = $latestfile_stat->ctime;
print "\nlatestfiletime = ".$temp;

$secondfile = "second_test.txt";
$secondstat = stat($secondfile);

$temp2 = $latestfile_stat->ctime;
print "\nprint again latestfiletime = ".$temp2;


$temp3 = $secondstat->ctime; #ERROR message on this line
print "\nprint again second file time = ".$temp3;
----------------------------------------------

Am I using stat incorrectly? Is there a way to call stats more than once?
Thanks,
msg

ericindc
06-08-2006, 11:35 AM
Trying adding a bit of error checking to your stat() call. It will give an indication of the problem. Likely the file you're stating doesn't exist.

stat("file.txt") or die "Unable to stat because: $!";