I want to find a chunk of data that's delimited on each size by a specific 4-byte sequence. This can be embedded anywhere in an arbitrary binary file.
My first idea is to set the $/ to this 4-byte sequence and then read using the normal <FILEHANDLE> syntax, examining each "record" until I see the one that looks like the one I want.
However, the random breaks in the file other than the two I want could be any length. I can imagine Perl getting bogged down reading gigaabyte strings into contiguous memory while scanning for the RecordSeperator, only to have me throw the data away as uninteresting!
If I could set a maximum length and a Seperator, or have a way to skip records without reading them, it would be great. But I don't see those abilities in the built-in Perl stream support.
Any suggestions on a portable, interesting, instructive, and efficient way to accomplish this?
—John
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.