in reply to Looping through a binary file
Instead, as noted by others, read only what you need -- one record at a time.
A common approach is to use a flag variable to indicate when you reach end of file; control the loop based on that.
Two ways to do this:
my $TRUE = 1; my $FALSE = 0; [...] my $EofFlag = $FALSE; while(!$EofFlag) { [...] my $cmtseq_cnt = read(perlIN,$cmtseq,5); if ($cmtseq_cnt < 5) { $EofFlag = $TRUE; # Redundant, given what we do next, but h +ere for example last; } }
|
|---|