I'm trying to parse an avi header and I'm having problems getting the actual values of the integer data in the file.
Here's what I do:
open(INHANDLE, "tesmovie.avi.mp3") || die("can't open file");
my $line = <INHANDLE>;
my $datarate = substr($line, 4, 4) - 0; print "$datarate\n";
What I'm trying to do here is read the data rate, which is a 4 byte integer into $datarate... but I always get 0... How do I treat a string and convert it's actual bit value to a long integer?
You can do something like this: (UNTESTED)
use Fcntl ':seek';
my $file = 'tesmovie.avi.mp3'; my $offset = 4; my $length = 4;
open my $fh, '<', $file or die "Cannot open $file: $!"; binmode $fh or die "Cannot binmode $file: $!"; seek $fh, $offset, SEEK_SET or die "Cannot seek on $file: $!"; read $fh, my $data, $length or die "Cannot read from $file: $!";
my $datarate = unpack 'I', $data;
Note that 'I' may not be the correct format. See the documentation for pack() for more details:
perldoc -f pack perldoc perlpacktut
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>