in reply to Getting next line after matched one
The short answer is that you need to use $nextLine = <INPUT> to get the next line after you match, then use last to leave the loop.
Here's something I patched together:
When I run it on itself I get the following:#!/usr/bin/perl -w # Next After Match .. PM node 418383 my $filename = shift; open ( INPUT, $filename ) or die "Unable to open $filename: $!"; my $string = shift; my $nextLine; while(<INPUT>) { if ( /$string/ ) { $nextLine = <INPUT>; last; } } close ( INPUT ); if ( defined ( $nextLine ) ) { print "INFO: $string found in file $filename, next line is:\n"; print $nextLine; } else { print "INFO: $string not found in file $filename.\n"; }
Seems to work.[foo@bar dev]$ perl -w nam.pl nam.pl print INFO: print found in file nam.pl, next line is: print $nextLine; [foo@bar dev]$ perl -w nam.pl nam.pl whoosat INFO: whoosat not found in file nam.pl.
Alex / talexb / Toronto
"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds
|
|---|