Re: reading a few bytes into a file
- From: jwkrahn@xxxxxxx (John W. Krahn)
- Date: Wed, 30 Jul 2008 12:43:19 -0700
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
.
- References:
- reading a few bytes into a file
- From: Scott Haneda
- Re: reading a few bytes into a file
- From: Rob Dixon
- Re: reading a few bytes into a file
- From: Rob Dixon
- reading a few bytes into a file
- Prev by Date: Re: Checking to see if file exists.
- Next by Date: XS
- Previous by thread: Re: reading a few bytes into a file
- Next by thread: How to get a computed string to act as a re in if statement
- Index(es):
Relevant Pages
|