in reply to Re: Search for a string in a file and get the string in the next line
in thread Search for a string in a file and get the string in the next line

There are two problems with reading from the file handle inside the while loop:
  1. To get robust code, you have to check if you're at the end of the file while reading from the file
  2. If you have two matching lines in a row, and both the second and the following line to be printed, you have to take special precautions

Which is why I generally prefer the approach of using a flag

use strict; use warnings; my $flag = 0; while (<DATA>) { if ($flag) { # print parts of $_ as necessary } $flag = /Ingress PSP/; }
Perl 6 - links to (nearly) everything that is Perl 6.
  • Comment on Re^2: Search for a string in a file and get the string in the next line
  • Download Code