in reply to Iteratively unpack structure from binary file

I would say that the first step is to find the length in bytes of the raw data block represented by  'i i f f f' (remembering that the data sizes of these template specifiers are implementation dependent).

c:\@Work\Perl>perl -wMstrict -le "my $template = 'i2 f3'; ;; sub template_len { my ($template) = @_; ;; my $s = pack $template; return length $s; } ;; my $buf_size = template_len($template); print $buf_size; ;; print template_len('i i f f f'); print template_len('i f3 i'); " 20 20 20
Knowing the size of a single raw block allows reading n raw blocks of data at a time with, IIRC, read or sysread (or the appropriate buffered-read built-in) and then unpack-ing with a template like "($template)n" or just "($template)*".

Replies are listed 'Best First'.
Re^2: Iteratively unpack structure from binary file
by ikegami (Patriarch) on Oct 20, 2014 at 18:33 UTC
    Well, read buffers, so,
    my $template = 'iifff'; my $rec_size = template_len($template); while (1) { my $rv = read($fh, my $rec, $rec_size); die "$!\n" if !defined($rv); last if !$rv; die "Premature EOF\n" if $rv < $rec_size; my @fields = unpack($template, $rec); ... }