in reply to How do I search this binary file?
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; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: How do I search this binary file?
by John M. Dlugosz (Monsignor) on Aug 20, 2002 at 22:19 UTC | |
by kschwab (Vicar) on Aug 21, 2002 at 00:50 UTC |
In Section
Seekers of Perl Wisdom