http://www.perlmonks.org?node_id=1007560

naturalsciences has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am working on multi GB text files. For now Perl has been good for working them line by line. Using the

while($line=<>){do_stuff_with_it_and_print_to_new_file}

Now I am in a need to read in files four lines at a time (as I need to do some comparisions in those quartets, but you can imagine that reading files in n lines at time would be helpful in several applications, etc. flat file with name\naddress\nbilling\nname\naddress\nbilling etc. for triplets.)

I was able to fulfill my desires for duplets easily with

 while($line=<>){$nextline=<>;do_stuff_to_those_poor_two_lines}, but an application of while($line=<>){$nextline=<>;$thirdline=<>} wont work anymore.

So how could I get on to reading and manipulationg my text files by any number of lines at a time I wish?

edit: I myself am thinking of somekind of while loop based thingy with possibly seek to keep those loops moving on in the filehandle. etc.