Rafaqat Ali Chaudhary wrote:
> 
> Following is the code:
>
> 1.    open(FILE, "< $l_file") ||
> 2.            die "Unable to open data file ($l_file)";

You should include the $! variable in your error message so you know why
the error occurred.

To make this code portable across different platforms you are going to
have to use binmode() on the filehandle.

        binmode FILE;


> 3.        for ( ;; ) {
> 4.            $length = read(FILE,$block,2048);
> 5.            if ( !defined($length) || $length == 0 ) {
> 6.                # Normal end of file
> 7.                last;
> 8.            }
> 9.            elsif ( $length != 2048 ) {

If read() returns less then the number of bytes requested it is not an
error.  You need to continue to read from the filehandle until you get
the required bytes or until read returns '0' or undef.


> 10.               # Unexpected end of file
> 11.               print "WARNING: Invalid last block length ($length)\n";
> 12.           last;
> 13.       }
> 14.       $blockcnt++;
> 15.       print "BLOCK $blockcnt\n";
> 16.       $reccnt = 0;
> 17.       # The first 4 bytes are the block descriptor word of which
> 18.       # the first 2 bytes is the length of valid data in the block
> 19.       $length = unpack("n", $block);###

The "n" template is an unsigned short in "network" (big-endian) order. 
Are you sure that the data was stored in this format?


> 20.       if ( $length > 2048 ) {
> 21.           # Bad valid data in block length
> 22.           print "WARNING: Invalid valid data in block length ($length)\n";
> 23.           last;
> 24.       }
>
> The Error Message: WARNING: Invalid valid data in block length
> (16412)
>
> The same message appears both on Red Hat Linux 7 and Windows 2000
> Advance Server.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to