Pragneshkumar Gandhi wrote:
> Hi All Perl Guru
> Is there any thing in perl to convert binary file to ascii

open the file and then binmode the file handle.  Then use unpack to
to unpack the binary data into vrbls.  Make sure you take into
consideration the byte order of the data (little-endian or big-endian).

> the file conatins following in binary format
> 
> HEADER
> 
> Transaction Code              short   2 Bytes
> Timestamp                     long    4 Bytes
> Message Length                short   2 Bytes
> 
>                                       Total   8 Bytes
> 
> DATA
> 
> Security Token                short   2 Bytes
> Last traded price             long    4 Bytes

Untested code example:

use strict;

my $buf;
my $file = 'somefile';

open IN, $file or die ...

read IN, $buf, 8 or die ...
my ($TC, $Ts, $ML) = unpack 'SLS', $buf;

read IN, $buf, 6 or die ...
my ($ST, $LTP) = unpack 'SL', $buf;

close IN;

__END__

-- 
   ,-/-  __      _  _         $Bill Luebkert   ICQ=162126130
  (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/

_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to