ok so i have an assignment and its all done except for one little thing i cant figure out...im sure its somthing simple i just cant see it
here is the program i have to do
Quote:
Code:
my output is like this
Code:
so it works perfectly except i wanted to make it comma separated without having a comma before the first element or after the last i cant seem to figure it out
here is the program i have to do
Quote:
and here is my code2. Write a program that reads a series of words (one word per line) until end-of-input, then prints a summary of how many times each word was seen. Sort the output in lexicographic order.
If the input were
Fred
Barney
Fred
Dino
Wilma
Fred
The output would be:
Barney: 1, Dino: 1, Fred: 3, Wilma: 1
Code:
Code:
my(@words, %count, $word);
chomp(@words = <STDIN>);
foreach $word (@words)
{
$count{$word} += 1;
}
foreach $word (sort keys %count)
{
print ("$word: $count{$word} " );
}
Code:
Code:
Barney: 1 Dino: 1 Fred: 3 Wilma: 1