regex - I'm matching a string and want to return the next three lines after the match -
regex - I'm matching a string and want to return the next three lines after the match -
i'm matching string , want homecoming next 3 lines after match. know $_ homecoming line i'm not sure look utilize homecoming next 2 lines in file have. here code have:
open $fh, '>', "${file}result.txt" or die $!; $fh->print("$file\t$_\n"); print "$_\n";
thanks in advance help , not making much fun.
keeping simple:
while (<$infile>) { if (/regex/) { $outfile->print($_); $outfile->print($infile->getline) 0 .. 1; } }
the io::handle
methods nice couple of reasons. $infile->getline
<>
, ever grabs 1 line (whereas <>
homecoming lines in list context). doesn't clobber $_
or warn @ end of file (although latter behavior desirable).
regex string perl line match
Comments
Post a Comment