in reply to reading binary files with Perl
Something like this should do it. See the docs and/or ask for anything you do not understand.
#! perl -slw use strict; my @grid; open my $fh, '<:raw', 'the file' or die $!; while( 1 ) { my( $recSize, $dummy, $record ); sysread( $fh, $recSize, 4 ) or last; $recSize = unpack 'N', $recSize; ##(*) sysread( $fh, $record, $recSize ) == $recSize or die "truncated record"; sysread( $fh, $dummy, 4 ) == 4 and unpack( 'N', $dummy ) == $recSize ##(*) or die "missing or invalid trailer"; ## (*) You may need V depending upon which platform your file was +created on push @grid, [ unpack 'N*', $record ]; } close $fh; ## @grid should now contain your data ## Addressable in the usual $grid[ X ][ Y ] manner. ## Though it might be $array[ Y ][ X ] ## I forget which order FORTRAN writes arrays in?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: reading binary files with Perl
by ikegami (Patriarch) on Nov 16, 2006 at 16:29 UTC | |
by BrowserUk (Patriarch) on Nov 16, 2006 at 19:17 UTC | |
by ikegami (Patriarch) on Nov 16, 2006 at 21:12 UTC |