|
|
Rob Dixon wrote:
use strict;
use warnings;
my $file = shift;
open my $fh, '<', $file or die $!;
print "Filename: $file";
my $buffer;
my $count = read $fh, $buffer, 8 or die $!;
die "Insufficient data in file" unless $count >= 8;
my $dv = unpack '@4 N', $buffer;
print " Value: $dv\n";
Or:
use warnings;
use strict;
use Fcntl ':seek';
my $file = shift;
open my $fh, '<:raw', $file or die "Cannot open '$file' $!";
printf "Filename: %-50s", $file;
seek $fh, 4, SEEK_SET or die "Cannot seek on '$file' $!";
read $fh, my $buffer, 4 or die "Cannot read '$file' $!";
4 == length $buffer or die "Insufficient data in file";
my $dv = unpack 'N', $buffer;
print " Value: $dv\n";
__END__
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
|
|