How about a find/rewind approach ?
Go ahead and set $/ to your delimiter,
but don't assign to a variable as you read.
(for the sake of conserving memory on huge
records)
Once you have the record boundaries, then
you could seek() back and process it however
you need to.
This is making the assumption that the bare
<FILE> construct isn't using memory.
I'm not clear on whether that's true or not.
#!/usr/bin/perl
my $delim="asdf";
$/=$delim;
open(FILE,"/some/big/file");
my $offset=0;
my $lastoffset=0;
for (;;) {
<FILE>;
my $offset=tell(FILE);
last if eof(FILE);
print "this record spans [$lastoffset] to [$offset], including";
print "the delimiter\n";
print " this means you could seek to $lastoffset and read for ";
printf "%d bytes to get the record\n",
$offset-$lastoffset-length($delim);
$lastoffset=$offset;
}
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.