Re: tricky problem about stat function-follow up

2005-11-13 Thread ZHAO, BING

On Sun, 13 Nov 2005 17:36:39 -0800
 ZHAO, BING [EMAIL PROTECTED] wrote:

opendir GOP, SCRATCH/BACKUP or die cannot open directory SCRATCH/BACKUP:$!;
my @smm=grep{($_ ne .)  ($_ ne ..)} readdir GOP;
foreach (@smm){
my($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
 $mtime, $ctime, $blksize, $blocks) = stat($_);
print $ctime;
} 
closedir GOP;



This piece of code WORKS when I point opendir GOP to the current directory. But it DOESNT work 
when I point to the subdirectory SCRATCH/BACKUP within the current directory.

It's tricky. And  print $_   successfully prints out the files in 
SCRATCH/BACKUP dir.


 By 'doesn't work', I mean $ctime is null.



What is the problem?

thank you all.

bing

--
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




Re: tricky problem about stat function

2005-11-13 Thread Jeff 'japhy' Pinyan

On Nov 13, ZHAO, BING said:

opendir GOP, SCRATCH/BACKUP or die cannot open directory 
SCRATCH/BACKUP:$!;

my @smm=grep{($_ ne .)  ($_ ne ..)} readdir GOP;
foreach (@smm){
   my($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
$mtime, $ctime, $blksize, $blocks) = stat($_);
   print $ctime;
} closedir GOP;


This piece of code WORKS when I point opendir GOP to the current directory. 
But it DOESNT work when I point to the subdirectory SCRATCH/BACKUP within the 
current directory.
It's tricky. And  print $_   successfully prints out the files in 
SCRATCH/BACKUP dir.


It prints the NAME of the file.  But that file doesn't exist in the 
current directory, it exists in the SCRATCH/BACKUP directory.  You need to 
prepend the directory path to the filename:


  foreach (@files) {
my $ctime = (stat SCRATCH/BACKUP/$_)[10];
  }

--
Jeff japhy Pinyan%  How can we ever be the sold short or
RPI Acacia Brother #734%  the cheated, we who for every service
http://www.perlmonks.org/  %  have long ago been overpaid?
http://princeton.pm.org/   %-- Meister Eckhart

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