in reply to File::stats issue

Could you show some code, what you're expecting, what you're getting, and maybe the output of "ls -l $filename" for each filename you're looking at?

It's really hard to tell what you're looking for from this. At least it is for me.

Replies are listed 'Best First'.
Re^2: File::stats issue
by basarix (Initiate) on Mar 14, 2005 at 20:28 UTC
    yes, sure... here's the code i am stuck on
    #!/usr/bin/perl use File::stat; use File::Basename; $srcdir = "/nfs/spptribu/"; $dstdir = "/trib/oper/temp/sql/eventual/"; $pgmFind="/trib/oper/temp/copiaFind"; open(DATOS,"$pgmFind|"); @datos = <DATOS>; close(DATOS) ; foreach $archivo (sort @datos) { #print "datos:$archivo"; ($perm,$nol,$owner,$group,$size,$mes,$dia,$hora,$filename) = split + (/\s+/, $archivo); $namefile=basename($filename,@suffixlist); $srcfile="$srcdir$namefile"; $dstfile="$dstdir$namefile"; # printf ("Archivo: %s \n\tPermisos: %s \n\tOwner: %s \n\tGroup: %s +\n\tSize: %s \n\tMes: %s Dia: %s Hora: %s\n",$filename, $perm,$owner,$group,$size,$mes,$dia,$hora); print "origen: $srcfile\n"; print "destino: $dstfile\n"; my ($src_dev,$src_ino,$src_mode,$src_nlink,$src_uid,$src_gid,$src_rdev +,$src_size,$src_atime,$src_mtime,$src_ctime,$src_blksiz e,$src_blocks)=stat($_); my ($dst_dev,$dst_ino,$dst_mode,$dst_nlink,$dst_uid,$dst_gid,$dst_rdev +,$dst_size,$dst_atime,$dst_mtime,$dst_ctime,$dst_blksiz e,$dst_blocks)=lstat($dstfile) or die "Cagaste! destino malo"; ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$bl +ksize,$blocks)=stat('/trib/oper/scripts/planesH.s.P370' ); print "$srcfile: $src_mtime $src_size\n"; print "$dstfile: $dst_mtime $dst_size\n"; exit; }
    i am trying to get an output similar to an "ls -l $filename" for each of the two files of each of the files in an array of filenames...
      Oops! Looks like you're using File::stat's stat command as if it were the perl built-in stat()! The first returns an object (or sets fields, potentially). The second returns a list of values, as you are expecting in your code.
        but on the documentation i could find on File::stat, it says that it overrides the functionality of the built in stat(), and gives just ONE example with 1 piece of code that suposedly works with the file mode.... i've not found the man/doc for File::stat very helpful, not does it give a detail of the fields it works with, or in what format are those, hence my problems...

      For starters, you're using $_ rather than $srcfile in your stat call. That call likely fails.

      Secondly, when you use File::stat, you are no longer using a stat or lstat that you see in perlfunc. You're using the ones found in File::stat. These return objects, not an array of items. So you'd get something like:

      my $src_stat = stat($srcname); my $dst_stat = lstat($dstfile); my $planesH_stat = stat('/trib/oper/scripts/planesH.s.P370'); printf "%s: %s %d\n", $srcfile, $src_stat->mtime(), $src_stat->size(); printf "%s: %s %d\n", $dstfile, $dst_stat->mtime(), $dst_stat->size();
        Tanktalus.... i've already tried to do something like that, but it gave me an error, complaining that the method couldn't be called on an undefined value....