in reply to Anti-slurp weblog

I'll second grep's suggestion that you look into database support and other already-invented wheels. That begs the question you asked, though, of how to be efficient about reading files, and what use could be made of $_ and $. in doing so.

As it happens, you posted this right after some cb discussion of readability, maintainability, C-style operators, and precedence. My suggestion here is an example of code I consider readable and all those other good things, but which depends crucially on "esoteric" details like operator precedence. I believe it to be highly optimized in the good way, by doing as little as possible inside the loop.

It sounds like you have most of the pieces in mind. Assuming WEBLOG is opened successfully, $sep is the record seperator, and $offset and $span are as you describe:

{ local $/ = $sep; my $done = $offset + $span ; while (<WEBLOG>) { chomp, print if $. == $offset .. $. == $done && last; } }
That uses the "flipflop" operator, .. in scalar context. It returns false until its first argument is true. Then it ignores its first argument and returns true until after its second argument becomes true. I use that so only one comparison is done for each record read. last is called to stop reading at that point, with && used because it has higher precedence than .. so that last is short-circuited out until it is needed.

chomp and print are done in sequence (comma operator) only if the flipflop is returning true.

After Compline,
Zaxo