use warnings;
$reff_filepath="/home/sharma/Documents/ref.txt";
open (CONFIG,"<","$reff_filepath")or die "Unable to open $reff_filepath: $!";
while(<CONFIG>) {
chomp;
@cols = (split(/ /))[2];
push(@array, @cols);
print "@array\n";
}
close CONFIG;
The output I got is:
On
On referendum
On referendum Bill
On referendum Bill overwhelming
On referendum Bill overwhelming claimed
On referendum Bill overwhelming claimed Bill
On referendum Bill overwhelming claimed Bill governmen
but my expected output is
On
referendum
Bill
overwhelming
claimed
Bill
governmen
Explaination: I’m trying to print the third word of each sentences using Perl. Above I have written my Perl script. I got that output what I expected in above. But I pushed that output into the array like this push(@array, @cols) then i got the first output what I mentioned above. Please anyone will give suggestion or to rewrite the Perl script to display the output I expect.
How about defining the input separator to “.”?
or something similar (I didn’t attempt to run this script). You don’t attempt to get every third word of each sentence but rather every third word in the entire document.