I am reading in large binary files (around 8MB) which contain records 1034 bytes long. My goal is to create a spreadsheet file that presents the data contained in the binary file in a nice human-readable format.
I accomplish this by reading one record at a time, parsing it, and then writing that line to the spreadsheet file.
Here is a simplified portion of my code:
#Read first record
$nNumBytesRead = read(FInputFile, $Data, 1034);
while($nNumBytesRead > 0)
{
#Reset Variables
$nOffset = 0;
@ItemList = ();
#Read Frame-Sync
@FrameSyncBytes = unpack("ccc",substr($Data,$nOffset,3));
$nOffset += 3;
#Place text data into @ItemList using ReadStatic()
ReadStatic(\@ItemList, \$nOffset, $U32, $U16, $Data, $SystemType);
#Print static data to output spreadsheet file
print FOutputFile ("\n",@ItemList);
# Read next record
$nNumBytesRead = read(FInputFile, $Data, 1034);
}
Notice that I write to FOutputFile every iteration. Is this an OK practice, or would it be worth it to setup a buffer so that I don't write to the disk as often?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.