I/O status Re: SPUG: proper checking of file status after read?

ced at carios2.ca.boeing.com ced at carios2.ca.boeing.com
Fri Sep 19 14:07:47 CDT 2003


> If you really don't want to consider a read of an zero length file an
> error, which may or may not be an issue for your app....  Then you'll
> have to do something like this:

> open(TEST, 'perlfiletest') or die "Couldn't open perlfiletest: $!";
> until (eof(TEST)) {
>   my $buffer;
>   read(TEST,$buffer,1024) or die "Read error on perlfiletest: $!";
> #  mystuff with file contents goes here
>...

FIONREAD from the Cookbook (recipe 7.15) might be a workaround 
by peeking first to see if there's anything there:

$size = pack( "L", 0 );
ioctl( TEST, $FIONREAD, $size ) or die $!; 
read( TEST, $buff, $size)  if $size = unpack( "L", $size);

[untested]

--
Charles DeRykus



More information about the spug-list mailing list