mardi 8 janvier 2019

problem to read line after the first string match

input file:
employment
work hard
good people

Perl script:

open(INFILE,"test_input.txt")||die "can't open the file";   
while(<INFILE>){    
$_=~s/^\s+//;    
$_=~s/\s+$//;    
    if ($_ =~ /work/){    
        <INFILE> or die "Bad file format";    
        my $model = INFILE;    
        print "line below search: $model\n";    
        if ($model =~/^good/){    
            print "found good word\n";    
        }    
        else{    
            print "no good word\n";    
        }    
    }    
}    

Expected Output:
line below search: good people
found good word

Actual Output:
line below search:
no good word

Question:
Any fixes needed in my script in order to get expected output?

Aucun commentaire:

Enregistrer un commentaire