Scan forward n lines from specified file offset

R

Robert Dodier

Hi,

Given a specified file offset, I want to scan forward n lines, and then
record the current file offset. I'm going to throw away the n lines
that
were read. What is a fast method of reading a number of input lines?
I could read one line at a time and loop n times, but I'm hoping there
is something faster than that.

Thanks for any light you can shed on this problem.

Robert Dodier
 
M

Mumia W. (reading news)

Hi,

Given a specified file offset, I want to scan forward n lines, and then
record the current file offset. I'm going to throw away the n lines
that
were read. What is a fast method of reading a number of input lines?
I could read one line at a time and loop n times, but I'm hoping there
is something faster than that.

Thanks for any light you can shed on this problem.

Robert Dodier

This does not answer your question directly, but you could use Tie::File
and let issue of seeking through lines be handled internally by that module.


host:~$ perldoc Tie::File
 
T

Tad McClellan

Robert Dodier said:
I could read one line at a time and loop n times, but I'm hoping there
is something faster than that.


Why?

Has it proven itself to be too slow for your application?
 
D

DJ Stunks

Robert said:
Hi,

Given a specified file offset, I want to scan forward n lines, and then
record the current file offset. I'm going to throw away the n lines
that
were read. What is a fast method of reading a number of input lines?
I could read one line at a time and loop n times, but I'm hoping there
is something faster than that.

Thanks for any light you can shed on this problem.

you may be able to modify the code layed out in

perldoc -q "How do I count the number of lines in a file?"

to suit your purposes.

-jp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top