Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening Large Files Question

Status
Not open for further replies.

vodkadrinker

Technical User
May 16, 2002
163
0
0
GB
I am currently looking at opening large files, wondered if someone could answer a query.

Perl:
open (FILE, '<', $file) or die "$!\n";
while (<FILE>) {
*Do stuff with line
}

a) When you use "open" does this read the whole file in before I start reading line by line?
b) If it does open the whole file is there a simple way to only open the last part of the file?
 
Now looking at "File::ReadBackwards.pm -- Read a file backwards by lines"

cpan.org said:
It works by reading a large (8kb) block of data from the end of the file. It then splits them on the record separator and stores a list of records in the object. Each call to readline returns the top record of the list and if the list is empty it refills it by reading the previous block from the file and splitting it. When the beginning of the file is reached and there are no more lines, undef is returned. All boundary conditions are handled correctly i.e. if there is a trailing partial line (no newline) it will be the first line returned and lines larger than the read buffer size are handled properly.

This was exactly what I was looking for, posted solution to help others
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top