I need help with the following assignment.
I've got the three words in the first line listed in an array. But I'm
stuck here. All I have to do is read the file and print the amount of
times each word in the array occurs:
this is what I have so far....
!/usr/bin/perl -w
open (INPUTFILE, "inputfile") or die "No input file, I'm going to die
now $!\n";
$Line_number = 1;
$. = 0;
do { $LINE = <INPUTFILE> } until $. eq $Line_number || eof;
for ( $LINE ) {
($word1, $word2, $word3) = split ( " ", $LINE);
@words = ($word1, $word2, $word3);
print "@words\n";
}
This should be easy... but I'm stuck
Here is the assignment:
2. Write a program that counts all occurrences of 3 words the user
wants counted in an input file. The input file consists of line 1 with
the 3 words the user wants to be counted separated by a space. The
actual input text starts with line 2 of the input file and will contain
0 or more occurrences of the words in line 1. Your program should read
the first line and store the 3 words the user input. It should then
read each word starting with line 2 and maintain a running count for
the 3 words identified in line 1. When your program reaches end of
file, it should output the counts for the 3 words. For example, the
input file may look like the following:
rain water cloudy
It was a cloudy day and the sky was overcast with dark ominous clouds.
It presently started to rain and the rain water started flowing along
the streets. The water from the rains started with a trickle, but
quickly developed into a massive torrent flooding all the low level
areas of the streets.
Your program should output the counts of 2 for rain, 2 for water, and 1
for cloudy.