Mr. Shawn H. Corey wrote:
On Sun, 2008-11-23 at 15:52 +0800, loody wrote:
The prototype of read is
read FILEHANDLE,SCALAR,LENGTH
ex:
read PATTERN, $line, 1920;
that means the $line will content 1920 bytes.
It means it will attempt to read 1920 bytes. The actual number of bytes
read is returned. Your code should look something like this:
my $bytes_read = 0;
while( $bytes_read = read( PATTERN, $line, 1920 ) ){
# do something with $line
}
if( ! defined( $bytes_read ) ){
die "error reading PATTERN: $!\n"
}
You shouldn't "do something with $line" if $bytes_read is undefined:
while ( my $bytes_read = read PATTERN, $line, 1920 ) {
unless ( defined $bytes_read ) {
die "error reading $filename: $!";
}
# do something with $line
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/