Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

How to read binary file with variable length in perl

by bh_perl (Monk)
on May 05, 2010 at 08:25 UTC ( [id://838463]=perlquestion: print w/replies, xml ) Need Help??

bh_perl has asked for the wisdom of the Perl Monks concerning the following question:

Hi..

I want to decode/encode a binary files which are contain fix length and variable length record.

Below is my file format.
Ericsson AIN records are stored in an input file in 2048 byte blocks. +Every block is made of variable length records padded to make a 2048 +byte blocks. Every record is made of a fixed 180 byte part. Records may contain add +itional tagged fields making the total length variable.
I am not sure either the file format belongs to ASN.1 or not and might be somebody could guide me.

Could somebody guide me where i can get the sample program or any manual guide on reading binary file with variable length or ASN.r file format.

Thank you, Baharin

Replies are listed 'Best First'.
Re: How to read binary file with variable length in perl
by moritz (Cardinal) on May 05, 2010 at 08:30 UTC
    • open the file with the :raw mode. See also: perlopentut. Put the file handle in binmode.
    • read as many bytes as you need
    • use unpack to extract the records you need. See also: perlpacktut
    • If necessary, use read again to obtain variable length records.
    • close the file
    • ...
    • PROFIT
Re: How to read binary file with variable length in perl
by Anonymous Monk on May 05, 2010 at 09:13 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: How to read binary file with variable length in perl
by marto (Cardinal) on May 05, 2010 at 09:42 UTC

    As anonymous monk points out, you've asked similar questions many times, is there something fundamental you're not understanding?

      Apparently he's missing the fact that no one here is going to write his code for him . . . :)

      Update: As (correctly) pointed out in a msg, append "(at least not for free)" in there.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        Hi...
        I am sorry about my question. I have never think that I want somebody to write any program for me.
        But, i raised a question here to solved my problem and get some guide from expert here on binary and ASN.1 file format.
        Anyway, thank you very much but please think positive. I will refer to my previos question or any related question about this.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://838463]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found