Pablo, Try one of the following subsubroutines. In the following example the binary subroutine is called with the first 4 bytes. The key is to understand how to use the unpack function.
Regards Mark $value = binary(substr($_record,0,4)); sub ib { # A signed integer value. my $_buffer = $_[0]; $ret = unpack("i*", $_buffer); return $ret; } sub IB { # An unsigned integer value my $_buffer = $_[0]; $ret = unpack("I*", $_buffer); return $ret; } sub char { # An char value my $_buffer = $_[0]; $ret = unpack("C*", $_buffer); return $ret; } sub pk { # A packed. my $_buffer = $_[0]; $ret = unpack("p*", $_buffer); return $ret; } sub binary { my $_buffer = $_[0]; $ret = hex(unpack("H*", $_buffer)); return $ret; } sub packed { my $_buffer = $_[0]; $ret = unpack("H*", $_buffer); return $ret; } sub binary8 { my $hex = unpack("H*", $_[0]); my $vec = Bit::Vector->new_Hex(64,$hex); my $ret = $vec->to_Dec(); return ($ret); } ----- Original Message ----- From: "pablo wablo" <[EMAIL PROTECTED]> To: <beginners@perl.org> Sent: Sunday, February 06, 2005 8:11 AM Subject: reading an integer value from file? > 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? > > Thanks hope you can help me > > > > __________________________________ > Do you Yahoo!? > Take Yahoo! Mail with you! Get it on your mobile phone. > http://mobile.yahoo.com/maildemo > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>