PerlJedi has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I have a binary file with the headder content (in HEX) as below (one single line).
This data should be unpacked to populate the following structure.0001000000004f914f1c0b010042534341303000000005000043413030303030000000 +014341303030313400000002434130303032320000000343413030303234000000044 +34130303032390000000100224e43656c6c3000000002004253434130310000000500 +054341303130303100000006434130313030340000000743413031303130000000084 +341303130313500000009434130313031360000000100224e43656c6c300000000300 +42534341303200000006000a
Header Record Id : 1 Byte File Format Version : 1 Byte Timestamp : 8 Bytes No. of BSCs : 1 Byte For each BSC ... BSC Id : 1 Byte Application Version : 1 Byte BSC Name : 2 Bytes Number of Cells : 2 Bytes For each Cell ... Cell Pointer : 2 Bytes Cell Name : 9 Bytes Number of Neighbour Cells : 2 Bytes For each Neighbour Cell to this BSC ... Cell Pointer : 2 Bytes Cell Name : 9 Bytes
Here is what I have been trying...
#! /usr/bin/perl -w open(FILE, "<A20120420.1257+0100-1302+0100_group0.bin"); binmode(FILE); my $headder = <FILE>; ($headderRecordId, $fileFormatId, $timeStamp, $noOfBSCs, $specOfBSCs) += unpack ("H2 H2 H16 H2 H*", $headder);
No doubt, I can decode the binary file this way. But here is what I prefer:
1. I need to convert the $noOfBSCs to Decimal, and then use it in a loop and then decode the data for the rest of the BSCs. Same would be followed for the Cells also.
> Is there a way that I can work without converting the read hex value in loops?
2. I do see that there is dynamic unpack possible also. But then I could not understand.
Since performance is a criteria, I dont want to code with C kind of logic. Please let me know as to how it can be done better in perl. Thanks in advance, PerlJedi
|
---|
Back to
Seekers of Perl Wisdom