in reply to Re^2: How to read number of block in binary files?
in thread How to read number of block in binary files?
This is because if the block contain 2 record the length is 604 while 3 record is 890 bytes. So that why i set $offset -= 286. is it correct ?
read( DATA, $data, BLOCKLEN, $offset );
is the same as saying:
read( DATA, my $temp, BLOCKLEN );
substr( $data, $offset ) = $temp;
and then the next statement:
my $blockhdr = unpack "H*", substr($data, 0, BLOCKHDR);
always extracts data from offset 0, at the beginning of $data
You need to read BLOCKHDR + BLOCKDATA data first, extract the $total_record value from that and then read $total_record * 286 data to get the actual records.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to read number of block in binary files?
by bh_perl (Monk) on Mar 10, 2009 at 02:31 UTC | |
by jwkrahn (Abbot) on Mar 10, 2009 at 10:24 UTC |