Hi ,
I am looking for some directions with this and posted the same question in one more forum.
am trying to get the word type as an output from an input file (input.txt) which looks like this,
Input file
John N N
loved V
Mary N N
. S
He N
was V
eating V
in P P
a A A
restaurant N
. S
The A A
cats N N
killed V
the A A
rats N N
. S
I N
am V
playing V
. S
The input file has three columns. The first column are the words and the next two columns are the word types. All the columns are separated by tab and there are blank lines in between. The objective of the program is to match the word endings like "ing","ed" and "s" and print the word types in the fourth column. The expected output will be
Expected output
John N N
loved V V
Mary N N
. S
He N
was V
eating V V
in P P
a A A
restaurant N
. S
The A A
cats N N N
killed V V
the A A
rats N N N
. S
I N
am V
playing V V
. S
The code that I am using is this,
!/usr/bin/perl
use warnings;
use strict;
open my $fh, '<' , 'input.txt' or die $!;
while (<$fh>) {
chomp ;
print $_;
if (/ing\s*$/ or /ed\s*$/) {
print ' V';
}
if (/s\s*$/) {
print ' N';
}
print "\n";
}
close($fh);
However I believe I am doing something wrong as I am getting the input file itself as the output. Please help me with some directions. Thanks in advance.