Perl - read between lines in a file - TechRepublic
General discussion
May 17, 2004 at 11:56 AM
cpfeiffe

Perl – read between lines in a file

by cpfeiffe . Updated 22 years ago

All,
I’m trying to find a simple way to read between lines in a file with perl.

For example a file might contain…
A
bunch of lines
B
bunch of lines
C
bunch of lines
D

And I want to read the “bunch of lines” between line B and line C.

I have the file handle and can read line by line just fine so the basic part is done. I just want to be selective on what lines I’m reading. The result goes into an array, but I only want to add lines between B and C in the array. I can do this with a couple of loops but that is messy and I’m hoping someone will have a better idea. I will know what B and C are, but not what the other lines are.

Thanks for any suggestions.

This discussion is locked

All Comments