Binary Files / Pack Function

Hi,

My name seems to be littered all over the message board for replies, but now I'm asking a question! :-)

I'm playing with binary files in Perl, or rather trying to. As I'm into digital audio, I figured the first step would be to try and write a routine that read in the header from a WAVE file. So, I wrote this:-

[code]
use Strict;

#Get filename.
my $wavefile = shift(@ARGV);

#Open file in binary mode.
open FILE, "<$wavefile";
binmode FILE;

#Get details of file.
my $chunkname = "";
my $datalength = 0;

#Get RIFF header.
read FILE, $chunkname, 4;
read FILE, $datalength, 4;
$datalength = pack('L', $datalength);

#Other stuff would go here...

#Close file.
close FILE;

#Print details.
print "Header: $chunkname
Length Of Data: $datalength
";
[/code]

$chunkname ends up containing "RIFF" as it should. $datalength, the next 4 bytes, is a 4 byte unsigned long integer, and I believe I am using the correct template in the pack function. However, for some reason, $datalength comes out empty after the call to pack(). Before that function, it contains the 4 character equivalent, but it's a bit meaningless like that!

Any ideas, please?

Thanks a lot,

Jonathan



-------------------------------------------
Count your downloads:
http://www.downloadcounter.com/
And host your site:
http://www.incrahost.com/
Don't say I never give you anything... ;-)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories