Thanks John and Peter for the reply.

Ok, to make this question more specific, the author of this book is making
a program to check if the files can be read off from the disk.
And he does so by checking two steps, first is making sure the meta data of
this file looks fine, and secondly by reading byte by byte from this file
to actually check the file's content readability.

this is the whole subroutine for checking the file :

sub CheckFile {
my $name = shift;
print STDERR 'Scanning ' . cwd . '/' . $name . "\n";
# attempt to read the directory entry for this file
my @stat = stat($name);
if ( !$stat[4] && !$stat[5] && !$stat[6] && !$stat[7] && !$stat[8] ) {
return 0;
}
# attempt to open this file
open my $T, '<', "$name" or return 0;

# read the file one byte at a time, throw away actual data in $discard
for ( my $i = 0; $i < $stat[7]; $i++ ) {
my $r = sysread( $T, $discard, 1 );
if ( $r != 1 ) {
close $T;
return 0;
}
}
close $T;
return 1;
}

and I cut the meta data checking part in the previous post.

Thanks
Frank


On Sun, Dec 11, 2011 at 12:39 AM, Peter Scott <pe...@psdt.com> wrote:

> On Sat, 10 Dec 2011 11:11:15 -0400, frank cui wrote:
> > # attempt to read the directory  entry for this file my @stat =
> > stat($name);
> > if ( !$stat[4] && !$stat[5] && !$stat[6] && !$stat[7] && !$stat[8] ) {
> > return 0;                        # according to the code context, here
> > it is saying the file is NOT ok
>
> What is the program trying to accomplish?  What does "ok" mean for a file
> in the context of this exercise?  The empirical derivation from the code
> doesn't seem useful.
>
> --
> Peter Scott
> http://www.perlmedic.com/     http://www.perldebugged.com/
> http://www.informit.com/store/product.aspx?isbn=0137001274
> http://www.oreillyschool.com/certificates/perl-programming.php
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

Reply via email to