Link to home
Start Free TrialLog in
Avatar of yuk99
yuk99Flag for United States of America

asked on

Read binary file with known structure

Hello,
I have to get a string from binary file. But to get it have to parse the file. Fortunately it's structure is known, but some parts size defined by integer numbers in the file. So it goes like this:
integer (4 bytes, little-endian)
integer
unsigned short (2 bytes)
unsigned short
integer
char [length defined by the integer above]
integer
char [length defined by the integer above]
...
...
I need to get the last string of chars above (it's not the last in the file).
My problem is I cannot get integers out of binary stream to determine the size of string after it.
Would you help please? Please use only standard Perl, no libraries.
ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yuk99

ASKER

Adam, thank you so much! Works great!
I heard I should use unpack, but could not understand how to use it. You made my day. Thanks!