I would like to match a pattern from the following data set and print the line containing that pattern plus the immediate next line. Say I am interested in matching the pattern- FrNum: 1. If my program runs correctly for the following data set, the output should be :
GOP: 6 FrNum: 1 FrTyp: I
GOP: 6 FrNum: 10 FrTyp: P .
GOP: 67 FrNum: 1 FrTyp: I
GOP: 67 FrNum: 9 FrTyp: B
Data Set
GOP: 3 FrNum: 7 FrTyp: P
GOP: 3 FrNum: 14 FrTyp: B
.
GOP: 6 FrNum: 2 FrTyp: B
GOP: 6 FrNum: 6 FrTyp: B
.
GOP: 6 FrNum: 1 FrTyp: I
GOP: 6 FrNum: 10 FrTyp: P .
.
GOP: 31 FrNum: 8 FrTyp: B
GOP: 31 FrNum: 11 FrTyp: B
.
GOP: 32 FrNum: 8 FrTyp: B
GOP: 32 FrNum: 10 FrTyp: P
.
GOP: 36 FrNum: 2 FrTyp: B
GOP: 36 FrNum: 13 FrTyp: P
.
GOP: 60 FrNum: 4 FrTyp: P
GOP: 60 FrNum: 5 FrTyp: B
.
GOP: 67 FrNum: 1 FrTyp: I
GOP: 67 FrNum: 9 FrTyp: B
---------------------------
I am new to perl and so far the code I have written is not working. What changes do I need to make?
#!/usr/bin/perl -w
my $next1;
print "Please Enter Input File\n\n";
$input_file = <STDIN>;
open(INFILE, $input_file) or die "Can't open $input_file: $!";
while (<INFILE>)
{
if($_ =~ /GOP:\s([0-9]+)\tFrNum:\s([0-9]+)\tFrTyp:\s([A-Z])/)
{
$_ = $next1;
if ($3 == 1)
{
print "$_";
print "$next1.\n";
}
}
}